首页 > angular controller 获取不到factory 里的数据 报错信息 is not a function

angular controller 获取不到factory 里的数据 报错信息 is not a function

这是factory 里的内容

angular.module('partsShopApp').factory('indexInfo',function($http,$q){
    return {
        query: function(){
            var deferred = $q.defer();
            $http.jsonp('http://xxx:8080/testIndex.html?callback=JSON_CALLBACK')
                .then(function(data,status,headers,config){
                    deferred.resolve(data);
                },function(data){
                    deferrd.reject(data);
                });
            return deferred.promise;
        }
    };
});

这是控制器里的内容

angular.module('partsShopApp').controller('home', ['indexInfo', '$scope','$q', function ($scope,$q, indexInfo) {

   indexInfo.query.then(function(data){
       $scope.data = data;
   },function(data){
       console.log('aaa');
   });
}]);

这是报错信息

如果 把 控制器 的内容改成 query()

angular.module('partsShopApp').controller('home', ['indexInfo', '$scope','$q', function ($scope,$q, indexInfo) {

   indexInfo.query().then(function(data){
       $scope.data = data;
   },function(data){
       console.log('aaa');
   });
}]);

会报错

怎么办呢?


注入服务顺序和控制器中的顺序不一样


控制器,注入与函数参数不对应,

【热门文章】
【热门文章】