Search code examples
angularobservable

How can I search for values contained in observable data fields?


 public rows$: Observable<any[]> = combineLatest([
    this.items$,
    this.term$,
  ]).pipe(
    map(([items, term]) =>
      items.filter(
        (item) =>
          term === "" ||
          item.product_name === term ||
          item.product_detail === term 

If we think in database logic, it can be interpreted as the use of like expression. Ex. Contains includes


Solution

  • You can use Object.values.includes to search for a value in an object like this

     public rows$: Observable<any[]> = combineLatest([
        this.items$,
        this.term$,
      ]).pipe(
        map(([items, term]) =>  items.filter((item) => Object.values(item).includes(term)))