I am expecting only one http request but in my console I am getting multiple http calls. I am not entirely sure the reason. Below is a abbreviated for ease of readability.
component.html
{{ (user | async).firstname }} {{ (user | async).firstname }}
<ul>
<li *ngFor="let profile of (user | async)?.profiles ">
<div>
<p>{{ profile.profileType }}<span *ngIf="isStudent(profile.specialized)"> - {{ profile.specialized }}</span></p>
<p>{{ profile.id }}</p>
</div>
<button class="btn btn-primary float-right" (click)="onGo(profile)">Go</button>
</li>
</ul>
component.ts
private user: Observable<User>;
ngOnInit(){
this.user = this.userDataService.fetchUserDetails(+params['id']);
}
UserDataService.ts
fetchUserDetails(id:number):Observable<User> {
console.log("calls 1 ?"); // this only gets called once!!!
return this.httpClient.get<User>(this.apiUrl + "/" + id)
.pipe(
tap((response) => {
console.log(response); // this is executed multiple times!!!
return response;
}),
catchError( (error) => {
handleIt();
})
)
}
In my console
In my network
What is making HttpClient to make so many http requests? when the UserDataService clearly only been executed once...


map?