1
我想根据employeemale.ts组件男性和女性定制的管道,当我在ngfor
循环使用女性定制管道过滤数据就说明根据女性的数据:角2自定义过滤器管问题
作品:
<ng-container *ngFor="let empLists of empList | filterdata:'female'">
但是当我使用它的人显示所有的JSON数据
不起作用:
<ng-container *ngFor="let empLists of empList | filterdata:'male'">
这是我的组件的HTML
<div class="widget box">
<div class="widget-header"> <h4><i class="fa fa-bars"></i> Female Employe Details</h4></div>
</div>
当我根据女性是过滤数据:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'filterdata'
})
export class FilterdataPipe implements PipeTransform {
transform(empList: Array<any>, arg: string): any {
debugger
return empList.filter(function(empLists){
//console.log(empLists)
return empLists.gender.toLowerCase().includes(arg.toLowerCase());
})
}
}
<div class="widget-content">
<table class="table table-bordered">
<thead>
<tr>
<th>#employee ID</th>
<th>Name</th>
<th>Gender</th>
</tr>
</thead>
<ng-container *ngFor="let empLists of empList | filterdata:'male'">
<tr>
<th>{{empLists.id}}</th>
<th>{{empLists.fullName}}</th>
<th>{{empLists.gender}}</th>
</tr>
</ng-container>
</tbody>
</table>
这是我的自定义管道filterdata.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'filterdata'
})
export class FilterdataPipe implements PipeTransform {
transform(empList: Array<any>, arg: string): any {
debugger
return empList.filter(function(empLists){
//console.log(empLists)
return empLists.gender.toLowerCase().includes(arg.toLowerCase());
})
}
}
是,男性被纳入女性'返回empLists.gender.toLowerCase()包括(arg.toLowerCase());' –
完成猜测,但是它可能与字符串“female”中出现“male”这个词有关吗? – DaveyDaveDave