I have the following rxjs stream:
this.universities$ = this.activatedRoute.queryParams.pipe(
switchMap((obj: any) => this.httpService.getUniversitiesList(this.numberOfRows, new URLSearchParams(obj).toString()).pipe(
tap((res: any) => {
this.totalPages = res.pagination.total;
if ((res.pagination.current_page > 1)){
setTimeout(() => this.paginator.changePage(res.pagination.current_page - 1));
}
})
).pipe(
startWith(null)
))
);
At the moment I have that rather ugly setTimeout
which sets PrimeNG's paginator number. Without it, I'd be trying to set it before the data is ready and therefore the number won't be set.
From what I've read I need to use the rxjs operator finalize
to do this properly. But I'm unsure where to place that. Do I need to pipe and switchMap after the tap?