AngularJs从self调用内部服务函数

前端之家收集整理的这篇文章主要介绍了AngularJs从self调用内部服务函数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经构建了一个提出多个请求的简单服务.该服务有两种方法.我无法在服务中调用另一个方法.

普兰克:http://plnkr.co/edit/2fERik4uTxbxlVOhncMd?p=preview

app.factory('Report',['$http',function($http){
var Authors = {

    reports : [],requests :[{'url':'data/data.cfm','response':'first'},{'url':'data.json','response':'second'},'response':'third'},'response':'forth'}],getReport : function(target,source,response,callback) {
    return $http({  url:source,method:"POST",params:{url : target}
                }).success(function(result) {
                    $scope.progress = response;
                    angular.extend($scope.user,result)
                    console.log($scope.user)
      }
      ).error(function(error){
                    $scope.progress = response
                })
},startQueue : function (target) {
        var promises = [];
        this.requests.forEach(function (obj,i) {
            console.log(obj.url)
            promises.push(getReport(target,obj.url,obj.response,function(value){
                reports.push(value);
                console.log(value)
            }));
        });
        $q.all(promises).then(function () {
            console.log("Finito");
        },function(error){
            console.log("errori")
        });
    }

};

return Authors;
}])

当我尝试从startQueue内部调用getReport时,我得到错误:未定义getReport.

将您的工厂更改为:
app.factory('Report',function($http){
    var Authors = {

        reports : [],};

    Authors.getReport = function(target,callback) {

    };
    Authors.startQueue = function (target) {

    };

    return Authors;
}])

猜你在找的Angularjs相关文章