我在注入我的收藏品工厂时遇到错误,但无法弄清楚我哪里出错:
错误:[$ injector:unpr] http://errors.angularjs.org/1.3.0/ $ injector / unpr?p0 =%24scopeProvider%20%3C-%20%24scope%20%3C-%20collections
'use strict';
var thangular = angular.module('thangular', ['ngAnimate']);
thangular.config(function ($interpolateProvider,$httpProvider) {
$interpolateProvider.startSymbol('[[').endSymbol(']]');
$httpProvider.defaults.useXDomain = true;
});
thangular.factory('collections', ['$scope', '$http', '$q',
function ($scope, $http, $q) {
return {
all: function () {
var deferred = $q.defer();
var request = $http({
method: 'GET',
url: '/collections.json',
});
request
.success(function (result) {
deferred.resolve(result.content);
})
.error(function (error) {
deferred.reject(error);
});
return deferred.promise;
}
};
}
]);
thangular.controller('mainCtrl', ['$scope', 'collections',
function ($scope, collections) {
collections.all().then(function (data) {
console.log(data);
});
}
]);
答案 0 :(得分:1)
我想你不应该在工厂申报中注入$scope
。只需改变
thangular.factory('collections', ['$scope', '$http', '$q',
到
thangular.factory('collections', ['$http', '$q',
工厂声明不应依赖于控制器$scope
。