0

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.

1
  • 2
    Which userService? The one passed as a dependency, or the one passed as a parameter in the login method? If you want the one that is declared in the services module, you should not be overriding the name in the login function. Either rename the parameter or remove it if you want to reference userService from the outer scope. Commented Jan 28, 2015 at 22:47

1 Answer 1

1

You are using a new function parameter called userService in your login method. simply use this line instead:

sc.login= function(sc){
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.