How can I configure the Http service adding headers to the call.
I try the following
class GlobalHttpHeaders {
static setup(Injector inj){
HttpDefaultHeaders http = inj.get(HttpDefaultHeaders);
http.setHeaders([{"X-Requested-With":"XMLHttpRequest"}], "COMMON");
}
}
And in the app the last line is:
Injector inj = ngBootstrap(module: new SiteIceiModule());
GlobalHttpHeaders.setup(inj);
But that don't work.
Have you tried something like this:
(I think) I got it working with:
I couldn't examine
http
to verify the headers because the debugger didn't show me the field but as stated in the comment when I applyheaders.setHeaders
do a map insideMyComponent
I get my custom header (this is whatHttp
does withheaders
) I usedDI 0.0.33
,Angular 0.9.9
I'm a little late to the discussion, but the answer provided was not usable for me, as my http requests are made by a 3rd party library. But I figured out a way to change the default headers.
You can access and modify the HttpDefaultHeaders object like a map.
This also works with 3rd Party libraries like hammock.
Note: I used angular 1.1.1 I don't know in which version this was added.