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