0

I am facing a problem with below code. It showing $http undefined in console. I have injected $scope and $http as well

SignInCtrl.$inject = ['$scope', '$http'];
function SignInCtrl($scope,$http) {
$scope.login = function($http) {   
return $http.post('/user/login', user).then(handleSuccess, handleError('Error creating user'));

};
}
1
  • remove the $http parameter from function. Commented Feb 27, 2017 at 13:29

2 Answers 2

4

Replace

$scope.login = function($http)

by

$scope.login = function()

The caller doesn't pass the $http service as argument. It's injected in the controller. So your function declaration hides the injected $http by the (undefined) one (not) passed as argument.

Sign up to request clarification or add additional context in comments.

Comments

-1
/**@inject*/
function SignInCtrl($scope,$http) {
    $scope.login = function() {
        return $http.post('/user/login', user).then(handleSuccess, handleError('Error creating user'));
    };
}

using /** @ngInject */ u can inject all dependencies you don't have to write all dependencies like (SignInCtrl.$inject = ['$scope', '$http']);

In $scope.login function you are passing $http which is not required you have injected already

1 Comment

While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.