I'm interested in adapting the following code for route resolvers.
private categorySubject = new Subject<number>();
categorySelectedAction$ = this.categorySubject.asObservable();
products$ = this.categorySelectedAction$.pipe(
switchMap(catId=>this.http.get<Product[]>(`${this.url}?cat=${catId}`))
.pipe(
tap(data => console.log(data)),
catchError(this.handleError)
));
selectedCategoryChanged(categoryId: number): void {
this.categorySubject.next(categoryId);
}
Should the resolver call selectedCategoryChanged and the return products$? My attempts to accomplish this do not return anything.
selectedCategoryChangedmethod in resolver, just return any value from resolver to not block the navigation. But more important question - why do you want to do this in resolver? Resolver primarily solves the issue when you want to load data as soon as possible, so you could just callhttp.getdirectly in resolver and bind the returned value to the component via input orroute.data. Why do you want to move this certain logic to resolver and not return anything from it?