Nathan Nathan - 6 months ago 45
HTTP Question

How to access response headers using $resource in Angular?

I basically call

requests like so:

var resource = $resource('/api/v1/categories/:id')

resource.get({id: 1}).$promise.then(function(data){

This works fine.. but how do I get the response headers?


You could use the transformResponse action defined here this would allow you add the headers

$resource('/', {}, {
    get: {
        method: 'GET',
        transformResponse: function(data, headers){
            response = {}
   = data;
            response.headers = headers();
            return response;

See a working example here JSFiddle