angularjs - Get response header in then() function of a ngResource object's $promise property after resource resolved? -


i'm willing retrieve response header of resource request, cause i've put pagination information , else in rather response body, make rest api clear.

though can success / error callback below:

object.get({type:'foo'}, function(value, responseheaders){     var headers = responseheaders(); }); 

where 'object' resource factory service.

further, when i'm trying make route change after required resources resolved, i've tried this:

.when('/list', {     templateurl: 'partials/list.html',     controller: 'listctrl',      // wait required promises resolved before controller instantialized     resolve: {         objects: ['object', '$route', function(object, $route){             return object.query($route.current.params).$promise;         }]     } }) 

and in controller, inject "objects" instead of object service, because it's resolved , filled in real data.

but got problem when try headers info "objects" in controller.

i tried objects.$promise.then(function(data, responseheaders){}), responseheader undefined.

how can change $resource service's behavior throws responseheader getter $promise then() callback function?

my service "object" reference:

myservices.factory('object', ['$resource',     function($resource){         return $resource('object/:id', {id: '@id'}, {             update: {method: 'put'},         });     } ]); 

i had exact same problem. used interceptor in resource definition inject http headers in resource.

$resource('/api/resource/:id', {     id: '@id'   }, {     index: {       method: 'get',       isarray: true,       interceptor: {         response: function(response) {           response.resource.$httpheaders = response.headers;           return response.resource;         }       }     }}); 

then, in then callback, http headers accesible through $httpheaders:

promise.then(function(resource) {     resource.$httpheaders('header-name'); }); 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -