I have an angular app where i want to first fetch a bunch of parent elements and then for each parent the corresponding children (1 parent to n children).
- Parent
- Child1
- Child2
- Parent
- Child1
- Parent3
- Child1
- Child2
- Child3
I currently fetch the parents by async-piping an observable. Up to this point everything seems to be ok.
Then I call a Function that should get me the corresponding children per parent. But then the Application goes berserk. The program send several HttpRequest and it seems like it is trying to refetch the children all the time. I cannot figure out what exactly is causing it, but I already assume it has something to do with the update-detection. But because parent$-Observable only gets updated once(when the http request finishes) I do not really know what else there could be that creates this loop of continuous reload.
getChild$() is a method that returns an observable from a http-request parent$ is an observable that only updates once in a runtime (request finishes)
<div *ngFor="let parent of parent$ | async">
{{parent?.name}}
<div *ngFor="let child of getChild$(parent.id) | async">
{{child?.name}}
</div>
</div>