I have a component which retrieves its business object from a single HTTP request, and then has several subsequent requests to populate drop-down lists. The arguments in those subsequent requests consist of data from the business object, so those requests can not begin until the first one completes.
Given an example resolver PersonResolver, this is the flow I want to achieve:
- Call
this.personService.getPersonData(). Returns typeObservable<PersonModel>. - Use the returned
PersonModelinstance, which we'll callpersonData, to callthis.personService.getAdditionalData1(personData.foo)andthis.personService.getAdditionalData2(personData.bar). Both return typeany[]. - Return type
Observable<PersonModel, any[], any[]>from theresolvemethod.
I would like to implement this into the component's resolver, but I am having a tough time wrapping my head around the correct usage of RxJS I need for the job.
Here's what I've got so far. I got stuck pretty quick.
constructor(private personService: PersonService) { }
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<PersonModel, any[], any[]> | Observable<Observable<PersonModel, any[], any[]>> | Promise<Observable<PersonModel, any[], any[]>> {
this.personService.getPersonData().subscribe(personData => {
// what to put in here?
});
}