I want to manually bootstrap an Angular 4 app (created with CLI).
In main.ts I am doing this:
const injector = ReflectiveInjector.resolveAndCrea
Possibly the original answer worked before, but in Angular 5 I was not able to use it, there was no definition for the function getAnnotations. This is what did work for me however:
import { ReflectiveInjector } from '@angular/core';
import {
HttpClient,
XhrFactory,
HttpHandler,
HttpXhrBackend,
HttpBackend
} from '@angular/common/http';
// https://github.com/angular/angular/blob/master/packages/common/http/src/xhr.ts#L45
export class BrowserXhr implements XhrFactory {
build(): any { return (new XMLHttpRequest()); }
}
const injector = ReflectiveInjector.resolveAndCreate([
HttpClient,
HttpXhrBackend,
{ provide: HttpBackend, useExisting: HttpXhrBackend },
{ provide: HttpHandler, useExisting: HttpBackend },
{ provide: XhrFactory, useClass: BrowserXhr},
]);
const http: HttpClient = injector.get(HttpClient);
http.get('/url').subscribe((response) => {
console.log(response);
});