Skip to content

Instantly share code, notes, and snippets.

@andyczerwonka
Created January 5, 2013 19:44
Show Gist options
  • Save andyczerwonka/4463263 to your computer and use it in GitHub Desktop.
Save andyczerwonka/4463263 to your computer and use it in GitHub Desktop.
How would get gain access to successF and errorF?
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);
});
}
};
} ]);
@andyczerwonka
Copy link
Author

In the final 'go' function, I can't get access to the successF and the errorF

@andyczerwonka
Copy link
Author

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