For some reason, I don't want to use constructor(private http: Http) DI.
Looked at https://angular.io/docs/ts/latest/api/http/index/Http-class.html
and tried
const injector = ReflectiveInjector.resolveAndCreate([
BaseRequestOptions,
XHRConnection,
{
provide: Http,
useFactory: (backend, defaultOptions) => new Http(backend, defaultOptions),
deps: [XHRConnection, BaseRequestOptions]
}
]);
this.http = injector.get(Http);
Error says
ORIGINAL EXCEPTION: Cannot resolve all parameters for 'XHRConnection'(?, ?, ?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'XHRConnection' is decorated with Injectable.
You need to provide
HTTP_PROVIDERS
:Actually, it can be as simple as
Based on Günter Zöchbauer's answer.