Filter Multiple Values using ngx-filter-pipe

Viewed 369

I am trying to filter an array using ngx-filter-pipe. I have successfully filtered if has a single value condition. I don't know how to filter any value in a array. Please help me out.

Angular

<input type="text" id="search"  class="form-control" name="search" [(ngModel)]="userFilter.name"> 
<tr *ngFor="let data of datas | filterBy: userFilter">
  <td>{{data.name}}</td>
  <td>{{data.age}}</td>
  <td>{{data.country}}</td>
</tr>

TS

userFilter: any = { name: '' };

Data

datas:[
  { name:"abc", age:17, country:"US" },
  { name:"xyz", age:25, country:"India" }
]

How should I handle my ngModel If put muliple parameters in userFilter

Stackblitz: Similar Example

1 Answers

The issue is with your filter.

The package expects the filter to be as below:

const filter = {
  name: {
    $or: ['abc']
  },
  age: {
    $or: ['17']
  }
  ...
};

As per the documentations

$or expects an Array.
Related