Javascript 过滤管不工作5
我正在尝试通过用户输入过滤firebase中的数据。我已经创建了一个管道来处理此问题,但我不断收到错误:Javascript 过滤管不工作5,javascript,angular,typescript,firebase,Javascript,Angular,Typescript,Firebase,我正在尝试通过用户输入过滤firebase中的数据。我已经创建了一个管道来处理此问题,但我不断收到错误: ERROR TypeError: Cannot read property 'indexOf' of undefined 我的html是: <div class="container-fluid"> <div class="col-md-6"> <input class="search" type="text" placeholder=
ERROR TypeError: Cannot read property 'indexOf' of undefined
我的html是:
<div class="container-fluid">
<div class="col-md-6">
<input class="search" type="text" placeholder="search proerties by post-code" [(ngModel)]="searchTerm">
</div>
<div class="row">
<div class="col-md-4" *ngFor="let property of properties | propertyFilter:searchTerm">
{{property.post_code}}
</div>
</div>
</div>
最后是我的烟斗:
@Pipe({
name: 'propertyFilter'
})
export class PropertyFilterPipe implements PipeTransform {
transform(properties: PropertyModel[], searchTerm: string): PropertyModel[] {
if(!properties || !searchTerm) {
return properties;
}
return properties.filter(property =>
property.post_code.indexOf(searchTerm) !== -1); //ERROR HERE
}
}
我已尝试将post_代码更改为我正在接收的对象中的其他字段,但仍然存在相同的问题。我猜这意味着信息永远不会到达这样的程度,因为它是未定义的
有什么建议吗 尝试添加
async
管道。它可能试图处理尚未提取的数据。@Sergey我在哪里添加该管道?内部*ngFor
post\u代码是什么类型的?如果其编号为/null,则在上没有可用的indexof方法it@AbineshDevadas返回一个字符串
@Pipe({
name: 'propertyFilter'
})
export class PropertyFilterPipe implements PipeTransform {
transform(properties: PropertyModel[], searchTerm: string): PropertyModel[] {
if(!properties || !searchTerm) {
return properties;
}
return properties.filter(property =>
property.post_code.indexOf(searchTerm) !== -1); //ERROR HERE
}
}