Nathan Nathan - 1 month ago 18
HTTP Question

How to access response headers using $resource in Angular?

I basically call

get
requests like so:

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

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


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

Answer

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

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

See a working example here JSFiddle