Created
January 5, 2013 19:44
-
-
Save andyczerwonka/4463263 to your computer and use it in GitHub Desktop.
How would get gain access to successF and errorF?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service.factory('userService', [ | |
'$http', | |
function($http) { | |
return { | |
name : 'User Service', | |
request : {}, | |
successF : {}, | |
errorF : {}, | |
login : function(user) { | |
this.successF = {}; | |
this.errorF = {}; | |
this.request = { | |
method : 'POST', | |
url : '/api/login', | |
data : user | |
}; | |
return this; | |
}, | |
success : function(func) { | |
this.successF = func; | |
return this; | |
}, | |
error : function(func) { | |
this.errorF = func; | |
return this; | |
}, | |
go : function() { | |
console.log('Executing ' + this.request); | |
$http(this.request).success(function(data, status, headers, config) { | |
successF(data, status, headers, config); | |
}).error(function(data, status, headers, config) { | |
errorF(data, status, headers, config); | |
}); | |
} | |
}; | |
} ]); |
Here's how I'm trying to call the service...
userService.login(user).success(function(data, status) {
$scope.status = status;
$scope.closeLoginDialog();
$window.location.reload();
}).error(function(data, status) {
$scope.status = status;
$scope.errorMsg = data;
}).go();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the final 'go' function, I can't get access to the successF and the errorF