[英]Injecting angularjs service inside a controller gives error
我試圖在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 c@http://localhost:8100/static/js/external/angular/angular.min.js:30....
您要插入的每個參數都需要在數組中列出。 請參閱此處的“數組符號”: http : //docs.angularjs.org/guide/di
.controller('HomeController',['$scope', '$window', '$http', '$cookies', 'globalDealListService',
function ($scope,$window,$http,$cookies,globalDealListService) {
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.