javascript - provide HTTP status to the success callback of $resource -
i need status code of factory promises, how can it?
myapp.factory('cartservice', ['$resource', function($resource){ return $resource('/api/v1/carts ', {}, { show: { method: 'get', isarray:false, headers:{'authorization':'token token=' + localstorage.token} }, create: { method: 'post', headers:{'authorization':'token token=' + localstorage.token} } }) }]);
this call
cartservice.show().$promise.then(function(data){ $rootscope.cart = data; // status ???? }).catch(function(response){ growl.warning("problems!!", {title: 'error'}); })
the response has status 204
as said in this answer,
you have add interceptor $ressource call. in interceptor, can add $http response promise response.
code this:
var resource = $resource(url, {}, { get: { method: 'get' interceptor: { response: function(response) { var result = response.resource; result.$status = response.status; return result; } } } });
i suggest check original answer.
Comments
Post a Comment