0
votes

I have a route resolver where I need to make two method calls in sequence that both return observables. I do not need to do anything with the response from the first call, but I would like to return to the component for the route the data that comes back in the second call. Can someone give me an example of how to do this? I think I should be using flatMap() but I cant seem to get it to work.

So basically: firstMethod(): Observable -> secondMethod():Observable <--return value from this.

1
Code example would be very helpful. At the moment it's hard to figure out why you are making two calls.Husein Roncevic

1 Answers

1
votes

You basically want something like this:

resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<string> {
      return this.someService.firstCall()
         .switchMap(res => this.someService.secondCall())
   }

You can also map the secondCall() to a more specific value if necessary.