0

I am trying to expose a response from the service to the controller via $rootScope.$emit('name', response.data), but it doesn't work.

My service:

/**API Post for user login*/
        function login(username,password){
            return $http.post('/api/login/',{
                   username:username,
                   password:password
            }).then(loginSuccessFn, loginErrorFn);

            function loginSuccessFn(response, status, headers, config){
                Authentication.setAuthenticatedAccount(response.data);

                window.location = '/';
            }
            function loginErrorFn(response, status, headers,config){
                $rootScope.$emit('errorLogin', response.data);
            }

          }

My Controller:

//Catching the Authentication.login errorFNn response.data
        $rootScope.$on('errorLogin', function(p){
            vm.isSuccess = p;
        })

and this is what happens in the view:

{"name":"errorLogin","targetScope":"$SCOPE","defaultPrevented":false,"currentScope":null}

can someone help me out

2
  • response.data is {"name":"errorLogin","targetScope":"$SCOPE","defaultPrevented":false,"currentScope":null}? Commented Jun 16, 2016 at 10:34
  • no, response.data is {status: "Unauthorized", message: "Username/Password combination invalid"} message : "Username/Password combination invalid" status : "Unauthorized" Commented Jun 16, 2016 at 10:36

1 Answer 1

1

Change:

$rootScope.$on('errorLogin', function(p){
    vm.isSuccess = p;
});

To:

$rootScope.$on('errorLogin', function(e, p){
    vm.isSuccess = p;
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.