用回调解决angular service 异步传输数据到controller中

来源:互联网 发布:蓝点网络 编辑:程序博客网 时间:2024/05/17 06:18
.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;

    }])

.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"});
})


0 0
原创粉丝点击