Within my ngOnInit function, I am looking for a way to ensure that all requests made by fetchLists are completed before moving forward:
ngOnInit(): void {
this.fetchLists();
this.route.params.subscribe(params => {
this.doSomethingWithFetchedLists();
}
});
}
fetchLists(): void {
this.httpHandlerCached.getListsA()
.subscribe(listA => this.listA = listA);
this.httpHandlerCached.getListsB()
.subscribe(listB => this.listB = listB);
this.httpHandlerCached.getListsC()
.subscribe(listC => this.listC = listC);
}
I would like to highlight that my previous inquiry was advised to use "forkJoin": Wait for multiple promises to finish
However, even after implementing forkJoin, I am facing the same issue:
fetchListnames() {
return forkJoin([
this.httpHandlerCached.getListsA(),
this.httpHandlerCached.getListsB(),
this.httpHandlerCached.getListsC(),
]).subscribe(res => {
this.listA = res[0];
this.listB = res[1];
this.listC = res[2];
});
}
Given the suggestion to use forkJoin, how can I ensure that the forkJoin operation is complete before proceeding (i.e., before calling
this.doSomethingWithFetchedLists()
)?