Reputation: 47
I have a variable queryCode
of type string
that depends on the value of route params so it is set under subscribe of activated route params and then using that value if it's null or not I call several other services.
I tried to use switchMap since other pieces of codes are dependent on queryCode
but I'm getting the error Argument of type '() => void' is not assignable to parameter of type '(value: Params, index: number) => ObservableInput<any>'. Type 'void' is not assignable to type 'ObservableInput<any>'.
Can somebody help me please?
this.route.queryParams
.pipe(
takeUntil(this.unsubscribe$),
tap(queryParams => {
this.queryCode = this.filterService.getCodeBasedQueryParams(queryParams); // this returns a string
}),
switchMap(() => {
if (this.queryCode) {
this.productService.dataLoaded$.subscribe((arrows: IAuctionArrows) => {
/// some code
});
this.productService.codeClosed$
.subscribe(() =>
this.productService.loadNextCode(this.queryCode));
}
}),
switchMap( () => {
this.productService.userLoaded$
.subscribe(product => {
this.typeOfProduct = this.product-service.getProductType(product);
if (this.queryCode && this.typeOfProduct) {
//some code
}
this.currentId = product.id;
this.router.navigate(['/product/' + this.currentId], { queryParamsHandling: 'preserve' });
});
}),
)
.subscribe();
Previously I had this, but this is not reliable since if the query code is set in async block and I do the checks without making sure that its value is set.
ngOnInit() {
this.route.queryParams.subscribe( params => {
this.queryCode =
this.filterService.getCodeBasedQueryParams(queryParams); // this returns a string
})
if (this.queryCode) {
this.productService.dataLoaded$
.subscribe((arrows: IAuctionArrows) => {
/// some code
});
this.productService.codeClosed$
.subscribe(() =>
this.productService.loadNextCode(this.queryCode));
}
this.productService.userLoaded$
.subscribe(product => {
this.typeOfProduct = this.product-service.getProductType(product);
if (this.queryCode && this.typeOfProduct) {
//some code this.currentId set here
}
this.currentId = product.id;
this.router.navigate(['/product/' + this.currentId], { queryParamsHandling: 'preserve' });
});
}
Upvotes: 0
Views: 542