I want to manually bootstrap an Angular 4 app (created with CLI).
In main.ts I am doing this:
const injector = ReflectiveInjector.resolveAndCrea
You can use HttpClient service before the Angular starts using ReflectiveInjector like this:
import { ReflectiveInjector } from '@angular/core';
import { HttpClient, HttpClientModule } from '@angular/common/http';
const injector = ReflectiveInjector.resolveAndCreate(getAnnotations(HttpClientModule)[0].providers);
const http = injector.get(HttpClient);
http.get('/posts/1').subscribe((r) => {
ConfigurationService.configuration = JSON.parse(config);
platformBrowserDynamic().bootstrapModule(AppModule);
});
This line:
getAnnotations(HttpClientModule).providers
references all providers that are registered on the HttpClientModule so you don't have to specify them manually. This answer explains the getAnnotations function in great details.
The approach I've shown is "sort of" the similar to what you're doing when importing HttpClientModule into the AppModule:
@NgModule({
imports: [HttpClientModule, ...],
})
export class AppModule {}
See this plunker for details.