title: Intercept all HTTP requests from angular2
body: <p>I'm looking for a way to intercept all HTTP requests made by the angular and add some <em>headers</em>. In releases prior to <code>angular2 RC5</code> (before <code>NgModule</code>) was that way, for example:</p>
  
  <pre class="lang-ts prettyprint-override"><code>class MyOptions extends BaseRequestOptions {
      Authorization: string = 'Bearer ' + localStorage.getItem('tokenName');
  }
  
  bootstrap(AppComponent,
      [HTTP_PROVIDERS,
          { provide: RequestOptions, useClass: MyOptions },
      appRouterProviders,
      disableDeprecatedForms(),
      provideForms(),
  ]).catch(err =&gt; console.error(err));
  </code></pre>
  
  <p>I am currently in version <code>2.0 final</code> and as <a href="https://stackoverflow.com/a/39249396/2290538">research on how this would be implemented in this version</a> would be something similar to this:</p>
  
  <pre class="lang-ts prettyprint-override"><code>@NgModule({
    imports:      [ BrowserModule ],
    declarations: [ AppComponent ],
    providers: [
      { provide: RequestOptions, useClass: MyOptions }
    ],
    bootstrap: [ AppComponent ]
  })
  export class AppModule {
  }
  
  @Injectable()
  export class MyOptions extends RequestOptions {
    constructor() { super({method: RequestMethod.Get, headers: new Headers()}); }
  }
  </code></pre>
  
  <p>It displays the following error: <code>TypeError: Can not read property 'merge' of null</code>. As can be seen <a href="http://plnkr.co/edit/yLyG16gDs6et6LkneVaC?p=preview" rel="nofollow noreferrer">this example</a>.</p>
  
  <blockquote>
    <p>Note: The implementation of <code>MyOptions</code> is the same as <a href="https://github.com/angular/angular/blob/master/modules/%40angular/http/src/base_request_options.ts#L182-L185" rel="nofollow noreferrer"><code>BaseRequestOptions</code></a>, copied, because if you use <code>BaseRequestOptions</code> in <code>{Provide: RequestOptions, useClass: BaseRequestOptions}</code>, everything works, as can be seen <a href="http://plnkr.co/edit/1gjgwdLt0RbXAqOSD8lh?p=preview" rel="nofollow noreferrer">this example</a>.</p>
  </blockquote>