我收到错误Cannot read property 'bind' of undefined
我创建了一个自定义过滤器来按名称过滤掉搜索字段,但我收到此错误并且无法越过它。任何帮助表示赞赏。 也跟进问题。在Angular2的最新迭代,我们不再添加过滤器:[FilterArrayPipe],@Component下,而是通过在NGModule声明app.module.ts增加吗?无法读取属性“绑定”未定义的搜索过滤器
filter.pipe.ts
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({name: 'filter'})
export class FilterArrayPipe implements PipeTransform{
transform(value, args){
if(!args || !args[0]) {
return value;
}
else if(value) {
return value.filter(item => {
for (let key in item){
if((typeof item[key] === 'string' || item[key] instanceof String)&&
(item[key].indexOf(args[0]) !== -1)) {
return true;
}
}
})
}
}
}
users.component.html
<div class="container">
<div class="input-group">
<input type="text" id="search" class="form-control" placeholder="Search Users" [(ngModel)]= "filterText">
</div><!-- /input-group -->
<br>
<table class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Username</th>
<th>Email</th>
<th>Phone</th>
</tr>
</thead>
<tbody *ngFor="let user of _users | filter: filterText" >
<tr>
<td>{{user.name}}</td>
<td>{{user.username}}</td>
<td>{{user.email}}</td>
<td>{{user.phone}}</td>
</tr>
</tbody>
</table>
</div>
在这行做你的错误? – Puigcerber
它没有指定,但它是管道|过滤器:触发它的filterText。查看上面添加的截图。 – user6680