문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top