Question

When adding 'loginService' as parameter to the controller to reference the service I want to use, it seems to cause an error as none of the rest of my angular functions work.

app.controller('loginController', function ($scope, loginService){

   $scope.loginUser = function () {
       loginService.login();
   }
});

However removing the service as parameter as shown below doesn't crash the rest of the sites angular functions, but obviously doesn't do the job I need.

app.controller('loginController', function ($scope){

   $scope.loginUser = function () {
       loginService.login();
   }
});

The service script has been declared. I'm very new to this and would appreciate any help. Thanks

Was it helpful?

Solution

If you copy the following code into the same file as your loginController code, does it work?

app.factory('testCtrl', function (){

    return {
        login: function(){
            console.log("DO SOMETHING GOOD WITH REGARDS TO LOGGING IN");
        }
    };
});

Then inject testCtrl into your controller. If it works, then We need to see your service.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top