I have an Angular-resolver that fetch data from the backend. I have the following calls to perform:
GetProject(projectId): Observable<IProject>
GetSites(projectId): Observable<ISites[]>
GetPersons(siteId): Observable<IPerson[]>
I'm trying to use combineLatest but not sure how to use RxJs in my scenario. I want all request to complete before resolving, but GetPersons() should have the id of the first item in GetSites() result as input. How is this done?
It looks more like you want to just concat several calls:
forkJoin([GetProject(projectId), GetSites(projectId)]).pipe(
concatMap(([project, sites]) => {
const siteId = /* whatever here */;
return GetPersons(siteId);
}),
).subscribe(...);
It also depends on whether you want to receive in the observer all responses or just the last one. If you want all responses then you'll need to chain GetPersons
with map
and append the first two responses:
GetPersons(siteId).pipe(
map(persons => [project, sites, persons]),
)