Below is a component Template I am working with:
<div *ngFor="let ctrl of data; trackBy:ctrl?.Id">
<div *ngIf="getNext(ctrl.nextDate) | async as next">
<span>{{next | date: 'dd.MM.yyyy'}}</span>
</div>
</div>
In this template, there is a method called getNext() that returns an Observable<Date>
:
public getNext(deadline: string): Observable<Date> {
return this.http.get<Date>(`${this.config.apiEndpoint}/api/meeting?deadline=${deadline}`);
}
My issue arises when I try to invoke the method and subscribe to the observable using the async pipe in the template. The problem is that when I run the application, it keeps generating endless GET and OPTIONS requests.
Even if I move the method call outside the ngFor loop, the same issue occurs. The call needs to be made inside the ngFor loop because the parameter varies for each collection item.
I'm puzzled as to why the method is only being called once and no additional calls are generated after the initial subscription?