0

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?

  • 3
    I think the `pipe(params => params)` is wrong`. pipe()` does only take rxjs operators like `map, filter, switchMap,..` as an argument – ChrisY Jan 16 '20 at 20:32

1 Answers1

0

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);
  }
DeborahK
  • 57,520
  • 12
  • 104
  • 129