组件.html:
<input
type="text"
[(ngModel)]="searchText"
placeholder="search your products here"
name="searchText">
<table class="table table-bordered">
<thead>
<tr>
<th>Id</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let obj of product| filter: searchText">
<td>{{obj.id}}</td>
<td>{{obj.description}}</td>
</tr>
</tbody>
</table>
过滤器.ts:
transform(items: any, searchText: string): any[] {
if (!items || !searchText || searchText === undefined) {
return items;
}
return items.filter(items =>
items.description.toLowerCase().includes(searchText.toLowerCase));
}
控制台显示项目。描述未定义。
模型.ts:
export class products{
id: number;
description: string;
}
在页面加载之前没有错误,一旦我开始在搜索框中输入,就会显示错误。错误显示在下面的代码中。
<input
type="text"
[(ngModel)]="searchText"
placeholder="search your issues here"
name="searchText">