I am trying to inject an Angularjs service inside an Angularjs controller but it gives me error.
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")
});
}
}]);
Could some one tell me what I am doing wrong?I am getting the below error in 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....
Each one of your parameters that's being injected need to be listed in the array. See "array notation" here: http://docs.angularjs.org/guide/di
.controller('HomeController',['$scope', '$window', '$http', '$cookies', 'globalDealListService',
function ($scope,$window,$http,$cookies,globalDealListService) {
...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.