I am using a factory recipe to call a method from controller, here is the factory definition.
app.factory('AccountService', function ($http){
var factory = {};
factory.getAuthenticate = function (credentials) {
$http({
method: 'post',
url: '/api/login',
data: credentials
}).success(function (data, status, headers, config){
return true;
}).error(function (data, status, headers, config){
return false;
});
}
return factory;
});
When I call getAuthenticate method from one of my controller,
app.controller('DefaultController', function ($scope, $location, AccountService){
$scope.login = function(){
alert(AccountService.getAuthenticate($scope.credentials));
// if(AccountService.getAuthenticate($scope.credentials)) {
// $location.path('/dashboard');
// }
}
});
It always returns undefined instead of true or false based on http calls. Any idea what I am missing?