【发布时间】:2017-05-13 16:38:13
【问题描述】:
我希望能够通过对类别名称执行搜索来搜索 categories 数组。我尝试了以下解决方案,但我不确定如何编辑管道中的变量以满足我的需要。
使用以下代码,控制台会记录以下错误。
categories.component.html:46:10 原因:item.indexOf 不是函数
Template
<tr *ngFor="let category of categories | textFilter:filterText">
<td>{{category.name}}</td>
<td>{{category.slug}}</td>
</tr>
Pipe
@Pipe({ name: 'textFilter' })
export class TextFilterPipe
{
transform(value: any, term: any) {
if (!term) return value;
return value.filter((item: any) => item.indexOf(term) > -1);
}
}
【问题讨论】:
-
您是否尝试在 google 控制台中调试并检查哪些方法项为您公开?
-
我不知道该怎么做..
-
在
returnvalue.filter之前添加console.log(value);...`
标签: angular angular2-pipe