In my controller, I call a service that logs the user in.
I want the service to report back to my controller whether the login has been successful or not. I tried putting return true
in my success(..)
function, but that doesn't seem to actually be returning anything.
My service:
loginRsrc.factory('loginSrvc', ['$http', function($http){
return {
http: function(){
$http({
method: 'POST',
url: "http://myproj.herokuapp.com/api/signIn",
data: $.param({email: "joe.gino@gmail.com", password: "1234567"}),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function(res){
console.log("res:");
console.log(res);
return true;
})
.error(function(res){
console.log("res");
console.log(res);
});
}
};
My controller
loginApp.controller('loginCtrl', ['$scope', '$state', 'loginSrvc', function($scope, $state, loginSrvc){
$scope.loginForm = {};
$scope.loginForm.email = "";
$scope.loginForm.password = "";
$scope.submit = function(){
loginSrvc.http();
// true? Then send user to other page