My angular 2.4.9 application A uses Http from @angular/http and another (3rd party) Angular Module B which itself also uses Http.
A -> http
A -> B -> http
In order to add generic HTTP headers, I've created a CustomHttp class in A that extends Http. I've injected it inside my app.module.ts like so
import AppComponent from './app.component';
import { Http, XHRBackend, RequestOptions } from '@angular/http';
import { CustomHttp } from '../myhttp/custom.http';
import { B } from 'some/thirdparty/module';
@NgModule({
bootstrap: [
AppComponent
],
declarations: [
AppComponent
],
imports: [
B.forRoot({ ... /* custom config */ })
],
providers: [{
provide: Http,
deps: [XHRBackend, RequestOptions],
useFactory: (backend: XHRBackend, defaultOptions: RequestOptions) => {
return new CustomHttp(backend, defaultOptions);}
}]
})
This works for all usages of Http inside my application module A. However, it does not work for the B dependency. All usages of Http inside B still seem to use the original class.
I know that DI in Angular works hierarchically https://angular.io/docs/ts/latest/guide/hierarchical-dependency-injection.html.
Is there a way to tell Angular also to inject CustomHttp in the usages of Http in B?