In my Angular app in my component i'm making two subscription to two Observables with switchMap that gets data from two API, when the component is opened i have to show a skeleton or a loader and i would prevent it, so i've just read about the Resolve which as i understand preload the data and then activate the route.
So i was wondering on how could i move the following subscription from ngOnInit to a Resolver
Here is how my ngOnInit looks like now
ngOnInit(): void {
this.menuService
.menu(this.idNegozio, this.piva, 'IT')
.pipe(
switchMap((menu) =>
forkJoin([
of(menu),
this.pluService.plu(this.idNegozio, this.piva, 'IT'),
])
)
)
.subscribe(([menu, plus]) => {
this.menu = menu;
this.plus = plus;
this.filterPlu(menu[0].id);
if (this.filteredPlu.length) {
this.ready = true;
}
});
}
And that same component is used in three routes:
{
path: 'asporto',
component: ProductsComponent,
canActivate: [ItemsGuardService]
},
{
path: 'takeaway',
component: ProductsComponent,
},
{
path: 'ecom',
component: ProductsComponent,
},