I created CustomHttp class which extends Http like here: http://restlet.com/blog/2016/04/18/interacting-efficiently-with-a-restful-service-with-angular2-and-rxjs-part-3/#comment-83563
I added providers to bootstrap like this:
bootstrap([
HTTP_PROVIDERS,
{ provide:Http,
useFactory: (backend: XHRBackend, defaultOptions: RequestOptions, errorNotifier: NotificationHandlerService,
authService: AuthInfoService) => {
return new CustomHttp(backend, defaultOptions, errorNotifier, authService);
},
deps: [ XHRBackend, RequestOptions, NotificationHandlerService, AuthInfoService]
},
])
All overriden methods(get, post, etc.) work fine. Then I added custom property and method to CustomHttp class and tried to access the property outside CustomHttp:
@Injectable()
export class CustomHttp extends Http {
...
private myCustomProperty = 'It`s custom';
public getCustomProperty() {
return this.myCustomProperty;
}
...
}
=====================
import {Http} from '@angular/http';
export class MainComponent {
constructor(private _http: Http) {
this._http.getCustomProperty(); // this method doesn`t exist in Http
}
}
How can I access custom methods and properties of CustomHttp?