用回撥解決angular service 非同步傳輸資料到controller中
阿新 • • 發佈:2019-01-02
.factory('test',["$http",function($http){
var testObject = {
data:{},
cb:function(){}
};
$http.get("/testRouter").then(function(err, data){
testObject.data = {"test":"test"};
testObject.cb();
}, function(msg){
testObject=msg;
});
return testObject;
var testObject = {
data:{},
cb:function(){}
};
$http.get("/testRouter").then(function(err, data){
testObject.data = {"test":"test"};
testObject.cb();
}, function(msg){
testObject=msg;
});
return testObject;
}])
.controller("fundrecordCtrl",["socket","$scope","$http","test",function(socket,$scope,$http,test){
test.cb = function(){
console.log(test.data);
}
}])
..................................................................................
router.get("/testRouter",function(req,res,next){
res.send({"testRouter111":"todfggh"});
})