![](/img/trans.png)
[英]How use sorting in ngx-datatable / ngx-datatable-column in Angular?
[英]How to pass multiple pipes for ngx-datatable-column in Angular?
我想問一下您是否有任何想法如何在Angular中傳遞多個管道?
目前,我的代碼僅傳遞一個管道。
const customPipe1 = new CustomPipe2();
const customPipe2 = new CustomPipe2();
<ngx-datatable-column
[width]="width"
[name]="cname"
[prop]="cbindProperty"
[pipe]="customPipe1">
</ngx-datatable-column>
我想在該列中添加兩個或多個管道。 在純HTML中類似這樣的內容。
{{ birthday | customPipe1 | customPipe2 }}
使用ngx-datatable
是不可能的。 您可以在源代碼中看到這一點 。
但是,您可以創建另一個執行相同操作的管道:
不必使用批注將其設置為Pipe
,因為您無需使用名稱,這樣您也不必將其添加到聲明中
export class ColumnPipe implements PipeTransform {
pipes: any[] = [
new BirthdayPipe(),
new CustomPipe1(),
new CustomPipe2()
];
public transform(input: any): any {
return this.pipes.reduce((output, pipe) => pipe.transform(output), input);
}
}
您的內部管道可能需要注入一些服務。 在這種情況下,您需要將管道與需要注入的管道一起添加到providers數組中,並將其注入ColumnPipe
的構造函數中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.