I am attempting to follow the tutorial on how to get route parameters in the Angular Routing documentation.
I am able to get the route parameters when using subscribe
.
this.getRouteParams$ = this.route.params.subscribe(params => {
// Works
console.log(params);
});
However according to the documentation it is best practice to use switchMap. I am unable to get the switchMap example to work in my code and I am not sure why.
import { switchMap } from 'rxjs/operators';
this.getRouteParams$ = this.route.params.pipe(
switchMap(params => {
// Does not work
console.log(params);
// How to check params here and then subscribe to other observables conditionally
})
);
The ultimate goal is to use switchMap to call other observables conditionally based on the value of the route parameters after they are received and validated. However I am unable to get even the first switchMap statement to work correctly as shown above.