-1

I am building a resolver that is used when my app loads initially. I need to run several HTTP requests, which can be run at the same time (hence using forkJoin). But there are a few that need to be chained once the forkJoin is completed. What would be the best way to accomplish this? I tried using mergeMap as follows:

  resolve(): Observable<any> {
return forkJoin([
  this.dataService.getUser(),
  this.dataService.getSummary()
]).mergeMap((data) => {
  return this.dataService.listDetails(data[1]);
});

}

However, I get the following error:

    ERROR Error: Uncaught (in promise): TypeError: (0 , rxjs__WEBPACK_IMPORTED_MODULE_1__.forkJoin)(...).mergeMap is not a function
TypeError: (0 , rxjs__WEBPACK_IMPORTED_MODULE_1__.forkJoin)(...).mergeMap is not a function

1 Answer 1

1

mergeMap is an operator. These need to be used inside the pipe method:

  resolve(): Observable<any> {
    return forkJoin([
      this.dataService.getUser(),
      this.dataService.getSummary()
    ]).pipe(mergeMap((data) => {
      return this.dataService.listDetails(data[1]);
    }));
  }
Sign up to request clarification or add additional context in comments.

3 Comments

I seem to be getting closer, however, I am unable to access the data returned by the first two requests in the forkJoin. I am accessing data via this.route.snapshot.data, but it only seems to include data from the last request. Any ideas?
I don't think I can answer that question with the given information. this.route.snapshot.data seems entirely unrelated to the Observable. Perhaps your issue is right there?
That is how I am accessing the data from the resolver, in the component in which I am routing to. The resolve method above is located in the InitialResolver, which is referenced in the route below. In BaseComponent, I am trying to access the data from the resolver. ` {path: "", component: BaseComponent, resolve: { data: InitialResolver }, },`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.