Observable syntax for filtering by URL parameters?

331 Views Asked by At

I am trying to filter a store subscription based on route params, but something about my syntax is not correct. I am trying to pipe the params down so the filter rxjs operator can filter the store the store based on the params:

selectedData;
@select(['data', 'selectedData']) selectedData$: Observable<any>;

  ngOnInit() {
    this.route.params
      .pipe(params => {
        return params
      }), switchMap(params => {
        this.selectedData$.pipe(filter(data => data.question === params))
      }).subscribe(data => this.selectedData = data);
  }

It says the params argument to switchMap() is of the wrong type...what is going wrong?

1

There are 1 best solutions below

0
DeborahK On

I'm not certain what you are trying to do, but the , after the pipe doesn't seem to be correct.

This seems syntactically correct, but not sure it will do as you want:

  ngOnInit() {
    this.route.params
      .pipe(params => 
        this.selectedData$.pipe(filter(data => data.question === params))
      ).subscribe(data => this.selectedData = data);
  }