How can I get my ngResource to accept custom headers?

My code in coffeescript:

  resource = $resource GlobalService.apiRoot + "stuffs", {},
    get:
      method: "GET"
      headers:
        "Accept": "application/stuffs;version=3"
        "Authorization": 'Token token="' + $.cookie('token') + '"'

My javascript code:

var resource;

resource = $resource(GlobalService.apiRoot + "stuffs", {}, {
  get: {
    method: "GET",
    headers: {
      "Accept": "application/stuffs;version=3",
      "Authorization": 'Token token="' + $.cookie('token') + '"'
    }
  }
});

Then when I do it.

resource.get ->

It does not send these specified headers and does not actually allow CORS authorization.

Any recommendations?

+5
source share
1 answer

It seems that the header settings are only available in the latest "erratic" release of Angular. If you are using this, be sure to upgrade both Angular.js and Angular.resource.js to 1.1.2 (current erratic version).

+4
source

All Articles