Angularjs – How to access response headers using $resource in Angular

angular-resourceangularjshttp

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?

Best Solution

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