In my app.config i need to retrieve a value from a service but i have an error message : UserServiceProvider.getUser is not a function. The goal is to allow the user to access some pages only if he is a part of a list.
Here's my service code :
var app = angular.module('myApp');
app.service('UserService', '$http', '$q', function(){
userService.getUser = function () {
var deferred = $q.defer();
return $http.get(userUrl + "getUserName")
.success(function (data) {
deferred.resolve(userService.userName = data);
console.log(data);
//alert('Success loading user');
}).error(function (error) {
deferred.reject(error);
//alert('Error loading user' + error.message);
})
return deferred.promise;
}
return userService;
});
My config :
app.config(function(UserServiceProvider){
UserServiceProvider.getUser()
.then(function (data) {
console.log(UserServiceProvider.userName);
});
});