컬렉션 팩토리를 삽입 할 때 오류가 발생하지만 어디에서 잘못되었는지 알 수 없습니다.
오류 : [$ 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);
});
}
]);
나는 당신이 $scope
공장 선언에 주입해서는 안된다고 생각합니다 . 그냥 바꿔
thangular.factory('collections', ['$scope', '$http', '$q',
...에
thangular.factory('collections', ['$http', '$q',
공장 선언은 컨트롤러에 의존해서는 안됩니다 $scope
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다