Following Angular docs, HttpClient
is injected into the app
component. I saw on another guide that this was a "favorable" without explanation.
@Component(...)
export class MyComponent implements OnInit {
results: string[];
// Inject HttpClient into your component or service.
constructor(private http: HttpClient) {}
ngOnInit(): void {
// Make the HTTP request:
this.http.get('/api/items').subscribe(data => {
// Read the result field from the JSON response.
this.results = data['results'];
});
}
}
On this I have some questions:
1) Where/How is the HttpClient actually instantiated? Does `ng serve` handle this?
2) How could I inject a different instance if I needed to?