I have this service that I am trying to access but it keeps saying that the service is undefined.
'use strict';
var $services = angular.module('services', []);
$services.factory('userService', function(){
return {
loginOnServer:function(){
console.log('enter function service');
}
}
});
Here is the controller
'use strict';
angular.module('kp.login', ['ngRoute', 'services'])
.controller('loginCtrl', ['$scope', 'userService', function(sc, userService) {
console.log("got to the controller");
sc.login= function(sc, userService){
console.log("call login on service");
console.log(userService);
userService.loginOnServer();
}
}]);
userService is undefined in the controller.
userService? The one passed as a dependency, or the one passed as a parameter in theloginmethod? If you want the one that is declared in theservicesmodule, you should not be overriding the name in theloginfunction. Either rename the parameter or remove it if you want to referenceuserServicefrom the outer scope.