I would like to read parameters from the URL and with that value then call an observable. If a result has been found I'd like to continue with it and call another observable. Ideally both calls are wrapped and I only have to subscribe once and I get both results back together.
This is my implementation so far:
this.route.paramMap.pipe(
switchMap(params => {
return forkJoin(
this.treeService.getTree(params.get('treeName')),
this.treeService.getTree(params.get('treeName')).pipe(
mergeMap(tree => this.fruitService.getFruit(tree.id))
)
)
})
).subscribe(res => console.log(res));
this works just fine, but I have to make 2 of the same calls .. how can I improve it so it only does one call to the treeService?