I have below code which invokes a service to get some values, I knowingly shut down the backend part to check if error is being added. I noticed it makes the service call twice, can someone explain me why this is happening?
(async () => {
try {
this.countries = await this.testerSvc.getCountries().toPromise();
} catch (err) {
this.addError("Countries");
}
})();
Service code:
getCountries() {
return this.http.get<[]>(this.baseUrl + "countries");
}
On my app.module.ts I had added my component:
bootstrap: [AppComponent, MyComponent]
On my app.component.html, I had
<app-tester> </app-tester>
It was instantiating my component twice, I removed from the bootstrap and now it's instantiating only once. So service call is only once.