Angular ng2-search-filter过滤多个

时间:2019-11-17 18:08:59

标签: angular angular-material

我正在将Angular 8与ng2-search-filter一起使用来过滤列表。

我有以下代码:

  <input class="form-control" type="text" placeholder="Search by Title, Keyword, or File Type.." name="search" autofocus [(ngModel)]="filterBar"> 

...

<tr *ngFor="let media of medias | orderBy: key : reverse | filter:filterBar | paginate: { itemsPerPage: 5, currentPage: p }; let i = index">
  <td>{{media.name}}</td>
</tr>

这可以按预期工作,并根据搜索栏中输入的值过滤列表。

问题

是否可以过滤两个项目?

我想添加一个下拉框,如果用户选择一个项目,它也会在该项目上进行过滤。

例如:

            <mat-form-field>
              <mat-label>Order By</mat-label>
              <mat-select [(value)]="selected">
                <mat-option *ngFor="let media of medias">{{media.type}}</mat-option>
              </mat-select>
            </mat-form-field>

<p>You selected: {{selected}}</p>

我想要对所选media.type进行其他过滤。

更多信息:

这是json数据:

medias = [
    {
      "id":"1",
      "name": "Video File 1",
      "type": "Videos"
    },
    {
      "id":"2",
      "name": "Interactive Video File 1",
      "type": "Interactive Videos"
    },
    {
      "id":"3",
      "name": "Audio File 1",
      "type": "Audio"
    },
    {
      "id":"4",
      "name": "Image File 1",
      "type": "Images"
    },
    {
      "id":"5",
      "name": "Document File 1",
      "type": "Documents"
    },
    {
      "id":"6",
      "name": "Video File 2",
      "type": "videos"
    },
    {
      "id":"7",
      "name": "Audio File 2",
      "type": "Audio"
    },{
      "id":"8",
      "name": "Image File 2",
      "type": "Images"
    },{
      "id":"9",
      "name": "Video File 3",
      "type": "Videos"
    },{
      "id":"10",
      "name": "Document File 2",
      "type": "Documents"
    }
  ];

0 个答案:

没有答案