var app = angular.module('app',[]);
//in the html, the following 2 files are attached.
// <script src="lib/sockjs-0.3.4.min.js"></script>
// <script src="lib/vertxbus.min.js"></script>
app.factory('serverData',function(){
var eb = new vertx.EventBus('http://xxx.xxx.xxx.xxx');
var x = {};
eb.send( "com.find.web.ed",{"Em":'[email protected]',"Pw":'123'},
function(reply){
x = reply;
});
var fact = {};
fact.getData = function(){
return x;
};
return fact;
});
app.controller('mainController',function($scope,serverData){
});
In the above code, i am trying to declare a factory to get data from a vertex server. It is not working, can some one help.?
It is working well when It is used in a controller. See the code.
var app = angular.module('app',[]);
app.controller('mainController',function($scope,$log){
$rootScope.user = {user :'[email protected]',password :'123'};
$rootScope.reply = {};
$scope.eb = new vertx.EventBus('http://100.100.100.100:8000');
$scope.loginFunction = function(){
$scope.eb.send( "com.find.web.ed",
{"Em":$scope.user.user,"Pw":$scope.user.password},
function(reply){
$rootScope.reply = reply;
$log.warn($rootScope.reply);
}
);
}
});
eb.send()method and populatexwithout using Angular? Assuming the event bus code works, are you hoping to calleb.send()every timeserverData.getData()is called?