0

I am new to angularjs. I cannot understand the behavior of angularjs for $http service callbacks (success and error).

I have a simple code code which calls an api outside my app and get the response. Up to here every thing works well. The problem is that I cannot return the response from the success or error callback. It must be assigned to a variable. and after error call back I can return the variable. Also if I use a simple variable it destroys my variable after assigning and the variable become undefined after callbacks. I have to define a variable as an object and then assign the response to a property of this object.

Here is my Code:

function getCategories(category_id, formMode){
      var req = ajaxCallFactory.get('admin/catalog/categories/'+ 
                   category_id + ((formMode) ? '/create': ''));
      var result = {};

      req.success(function(response){
            result.list = response;
      });

      req.error(function(response){
      });

      return result;
}
digit
  • 4,479
  • 3
  • 24
  • 43

0 Answers0