0
我有一個管道過濾器,它通過name
過濾我的客戶端列表。我需要添加其他過濾器,使客戶可以通過account_number
被過濾管道過濾器:使用管道過濾器,使其在多個條件下工作
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({
name: 'filter',
pure: false
})
export class FilterPipe implements PipeTransform {
transform(items: any[], term): any {
return term ? items.filter(item => item.name.toLowerCase().indexOf(term.toLowerCase()) != -1) : items;
}
}
在我看來,我的過濾器綁定的方式是這樣的:
<input type="text" class="form-control" placeholder="Name" name="term" [(ngModel)]="term">
<input type="number" class="form-control" placeholder="Account number"> <!--Here I want to make another ngModel-->
<table>
<tr *ngFor="let client of clients | filter: term | sortBy: 'id'; let i = index"
<td>{{client.name}}</td>
<td>{{client.account_number}}</td>
</tr>
</table>
所以,做我需要爲另一個屬性過濾另一個pipe
,或者可以在一個pipe
中完成嗎?另外,如果它是兩個不同的管道,我應該如何將它包含在視圖中的過濾器中?謝謝。
不幸的是,我發現了一個錯誤:'錯誤類型錯誤:v [K] .toUpperCase不是function' –
你有什麼用繩子嘗試或號碼? –
當使用數字或字符串獲取錯誤時,我嘗試了兩種變體 –