How do you set global custom headers in Angular2?
- Change
MyOptions
to:
class MyOptions extends RequestOptions { constructor() { super({ method: RequestMethod.Get, headers: new Headers({ 'Content-Type': 'application/json', 'X-Some-Header': 'some-content' }); }); }}
- Put
provide(RequestOptions, {useClass: MyOptions})
AFTERHTTP_PROVIDERS
(otherwise defaultBaseRequestOptions
will be used instead of yourMyOptions
).
bootstrap(App, [ // ... HTTP_PROVIDERS, provide(RequestOptions, {useClass: MyOptions}) // <- after HTTP_PROVIDERS!!!])
See this plunk