这是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');
});
}]);
会报错
怎么办呢?
注入服务顺序和控制器中的顺序不一样