How do you set global custom headers in Angular2? How do you set global custom headers in Angular2? angular angular

How do you set global custom headers in Angular2?


  1. Change MyOptions to:
class MyOptions extends RequestOptions {  constructor() {     super({       method: RequestMethod.Get,      headers: new Headers({        'Content-Type': 'application/json',        'X-Some-Header': 'some-content'      });    });  }}
  1. Put provide(RequestOptions, {useClass: MyOptions}) AFTER HTTP_PROVIDERS (otherwise default BaseRequestOptions will be used instead of your MyOptions).
bootstrap(App, [  // ...  HTTP_PROVIDERS,  provide(RequestOptions, {useClass: MyOptions}) // <- after HTTP_PROVIDERS!!!])

See this plunk