Angular 2从包含另一个对象的对象中搜索管道过滤器?
问题描述:
我想实现包含对象的对象的搜索。 我想使用角度搜索过滤器来过滤Property_id参数。我如何才能在“property_id”对象上应用搜索过滤器。Angular 2从包含另一个对象的对象中搜索管道过滤器?
答
如下您可以创建一个管道,
@Pipe({name: 'filterByPropertyId'})
export class FilterByPropertyId implements PipeTransform {
transform(yourList: yourObject[], property_id: string): any[] {
if (yourList) {
return yourList.filter((yourList: yourObject) => list.property_id === property_id);
}
}
}
,并在组件级
<div *ngFor="let r of yourList| FilterByPropertyId:propertyId">
</div>