ngResource Dynamically Set Header on Each Request

喜欢而已 提交于 2019-12-02 05:54:17

I have to be able too set headers dynamically on each request :

To set the header on each request, make the header a function:

{ Authorization: function(config) {
                     return 'Bearer '+ myAuthService.getToken(); 
                 }
}

From the Docs:

  • headers – {Object} – Map of strings or functions which return strings representing HTTP headers to send to the server. If the return value of a function is null, the header will not be sent. Functions accept a config object as an argument.

By furnishing a function, the header value will be computed on each request.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!