Within this specific scenario, your objective is to guide the user through a process involving two service calls to distinct endpoints. Upon receiving responses from these endpoints, you aim to merge them using fork join before passing them on to the component as an observable.
However, it seems that you are seeking a method to initiate the http calls prior to redirecting to the page in question. Angular router offers a suitable solution for this situation.
You have the option to designate which http calls should be executed even before the user reaches a certain page.
To achieve this, implement resolve at the service level and include that service within the route resolve function.
For example :
import { Injectable } from '@angular/core';
import { APIService } from './api.service';
import { Resolve } from '@angular/router';
import { ActivatedRouteSnapshot } from '@angular/router';
@Injectable()
export class APIResolver implements Resolve<any> {
constructor(private apiService: APIService) {}
resolve(route: ActivatedRouteSnapshot) {
return this.apiService.getItems(route.params.date);
}
}
Routes :
{
path: 'items/:date',
component: ItemsComponent,
resolve: { items: APIResolver }
}