我试图在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....
答案 0 :(得分:0)
正在注入的每个参数都需要在数组中列出。请在此处查看“数组表示法”:http://docs.angularjs.org/guide/di
.controller('HomeController',['$scope', '$window', '$http', '$cookies', 'globalDealListService',
function ($scope,$window,$http,$cookies,globalDealListService) {
...
}