我想在Angularjs控制器中注入一個Angularjs服務,但它給了我錯誤。在控制器內注入angularjs服務給出錯誤
service.js
angular.module('gbuyRef',[]).factory('globalDealListService'.function(){
var globalDealList = {};
return {
getGlobalDealList: function() {
return globalDealList;
},
setGlobalDealList: function (value) {
globalDealList = value;
}
};
})
Controller.js
angular.module('gbuyRef').controller('HomeController',['$scope', 'globalDealListService', function ($scope,$window,$http,$cookies,globalDealListService) {
$scope.logOut = function() {
$http({
method : 'POST',
url : '/logOut',
headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
// set the headers so angular passing info as form data (not request payload)
}).success(function(data, status, headers, config) {
console.log($cookies.globalProductList)
$window.location.href="/static/html/login.html"
}).error(function(data, status, headers, config) {
$scope.status = status;
$window.alert("error")
});
}
}]);
能有一個人告訴我什麼,我做錯了什麼?我得到在Firebug下面的錯誤。
Error: [$injector:unpr] http://errors.angularjs.org/1.2.11/$injector/unpr?p0=globalDealListServiceProvider%20%3C-%20globalDealListService t/<@http://localhost:8100/static/js/external/angular/angular.min.js:6 Yb/l.$injector<@http://localhost:8100/static/js/external/angular/angular.min.js:32 [email protected]://localhost:8100/static/js/external/angular/angular.min.js:30....
'[ '$範圍', 'globalDealListService',函數($範圍,$窗口,$ HTTP,$餅乾,globalDealListService)'這些列表不匹配1 – hassassin
感謝@hassassin,那麼如何匹配呢? – tushR
使用angular.js代替angular.min.js以獲得更多可讀性的angular調試。你會看到注入鏈 – lib3d