Answer the question
In order to leave comments, you need to log in
How to override class constructor in Angular 2?
There is class A:
export class A {
constructor(protected http: Http) {
}
}
export class B extends A {
constructor(protected http: BetterHttp) {
console.log(http);
}
}
@Injectable()
export class BetterHttp extends Http {
constructor(backend: ConnectionBackend, defaultOptions: RequestOptions) {
super(backend, defaultOptions);
}
.....
}
@NgModule({
providers: [
{
provide: BetterHttp ,
useFactory: (xhrBackend: XHRBackend, requestOptions: RequestOptions) => {
return new SecurityHttp(xhrBackend, requestOptions, authService, router);
},
deps: [XHRBackend, RequestOptions]
}
]
})
export class CModule {
}
Answer the question
In order to leave comments, you need to log in
@NgModule({
providers: [
{
provide: BetterHttp ,
useFactory: (xhrBackend: XHRBackend, requestOptions: RequestOptions) => {
return new SecurityHttp(xhrBackend, requestOptions, authService, router);
},
deps: [XHRBackend, RequestOptions]
},
{
provide: Http,
useExisting: BetterHttp,
}
]
})
export class CModule {
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question