user1245524 user1245524 - 1 month ago 12
AngularJS Question

TypeError: AuthenticateService.checkUser is not a function

TypeError: AuthenticateService.checkUser is not a function

I am submitting a login page with credentials, for sending the credentials to the server I have service **AuthenticateService** with $http.post, calling the method in the above mentioned service from the contactLoginCtrl.js (controller),
during that I am encountering this error


below is the code for AuthenticateService

angular.module('app.services')
.service('AuthenticateService',['$http',function($http){

return{

checkUser : function(uname, pword){

var indata = { "password": pword, "username":uname };
var req ={
method: 'POST',
url: 'http://localhost:8083/spring2/login',
data: indata
}

$http(req).then(function (response) {
console.log(response);
return response;
}, function (error) {
console.log(error);
return error;

});
}

}

}]);


below is the controller code contactLoginCtlrls.js

angular.module('app.controllers')
.controller('contactLoginCtrl',['$rootScope','$scope','AuthenticateService','$location',function($scope,AuthenticateService,$location){

$scope.authenticate = function(userModel){
var userName = userModel.username;
var password = userModel.password;
console.log(userName+password);

***AuthenticateService.checkUser(userName,password);***
};

}])
The above highlighted line is causing the error could some one please check this?


----------------------ignore the below section------------------------


content added only for skipping the error from stackoverflow to add some more detail

Answer

You controller does not have $rootScope injected as a parameter. Change it like this,

angular.module('app.controllers')
.controller('contactLoginCtrl',['$rootScope','$scope','AuthenticateService','$location',function($rootScope,$scope,AuthenticateService,$location){