I have a service that transfers my API calls to Angular:
var ConcernService = { list: function (items_url) { var defer = $q.defer(); $http({method: 'GET', url: api_url + items_url}) .success(function (data, status, headers, config) { defer.resolve(data, status); }) .error(function (data, status, headers, config) { defer.reject(data, status); }); return defer.promise; },
Then my application configuration with UI-Router :
.config(function($stateProvider){ $stateProvider .state('default', { url: '/', resolve: { tasks: function ($stateParams, ConcernService) { return ConcernService.list('tasks/').then( function (tasks) { return tasks; }, function (reason) { return []; } ); }, ... } } });
This is the simplest configuration I could handle, which basically just returns an empty object if it encounters 403 , 404 , etc., and I can handle this in the view template.
My question is: what is the best approach for getting other details to the view / template, e.g. rejecting reason and status . Should it be returned to the tasks object or separately?
Any help is greatly appreciated.
source share