As a newcomer to RXJS, I am facing a particular challenge that I need help with.
I have two API calls, where the second call is dependent on the result of the first one. My issue lies in needing to handle both calls within a single subscription so that the finalize function triggers only after both subscriptions are completed. Currently, the finalize function triggers after the first observable finishes, not waiting for the second one to complete as well.
private getTemplate(){
this.loading = true;
this.service.getTemplate()
.pipe(
finalize(() => this.loading = false)
)
.subscribe(
(response) => {
if (response) {
this.createImage(response.link);
}
}
)
}
public createImage(link: string) {
this.service.createImage(link)
.subscribe(
(response) => {
this.image = response;
}
)