I have developed a CustomHttp class that extends Http similar to the example provided here:
To integrate this CustomHttp class, I included providers in the bootstrap function as shown below:
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 overridden methods like get and post are fully functional. However, when I added a custom property and method to the CustomHttp class, I encountered an issue trying to access it from outside the 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
}
}
Can anyone suggest how to access custom methods and properties of CustomHttp?