Nathan Nathan - 1 year ago 103
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download