如何使用ngModelChange过滤角度4中的对象值?

时间:2017-11-27 20:26:32

标签: javascript json angular

我试图创建一个输入字段,用于过滤使用ngFor生成的列表," description"财产名称。列表是这样的对象:

[
 { code: 001, description: "Product 001 description" },
 { code: 002, description: "Product 002 description" },
 { code: 003, description: "Product 003 description" },
 { code: 004, description: "Product 004 description" }
]

我的功能:

seachFilterData(e) {
    const query = e;
    this.filterData.map((items) => Object.values(items).forEach(value => {
      return Object.keys(value).filter(k => {
        if (value.toLowerCase().includes(query.toLowerCase())) {
          return items;
        }
      });
    }));
  }

HTML:

<input type="text" class="tokenfield-search" placeholder="search" [ngModel]="searchFilter" value="" (ngModelChange)="seachFilterData($event)">
<div class="tokenfield-list">
  <ul>
    <li *ngFor="let data of filterData | keys">

当我console.log(items)过滤时,但列表没有变化。有什么想法吗?

0 个答案:

没有答案