Javascript 如何在Angular中为ngx datatable列传递多个管道?
我想问一下,你是否有任何想法如何通过多个管道的角度 目前,我的代码只通过一个管道Javascript 如何在Angular中为ngx datatable列传递多个管道?,javascript,angular,pipe,ngx-datatable,Javascript,Angular,Pipe,Ngx Datatable,我想问一下,你是否有任何想法如何通过多个管道的角度 目前,我的代码只通过一个管道 const customPipe1 = new CustomPipe2(); const customPipe2 = new CustomPipe2(); <ngx-datatable-column [width]="width" [name]="cname" [prop]="cbindProperty" [pipe]="customPipe1">
const customPipe1 = new CustomPipe2();
const customPipe2 = new CustomPipe2();
<ngx-datatable-column
[width]="width"
[name]="cname"
[prop]="cbindProperty"
[pipe]="customPipe1">
</ngx-datatable-column>
这在使用ngx数据表时是不可能的。您可以在源代码中看到这一点 但是,您可以创建另一个执行相同操作的管道: 无需使用注释将其设置为
管道
,因为您不需要使用名称,这样您也不必将其添加到声明中
您的内部管道可能需要注入一些服务。在这种情况下,您需要将管道与需要注入的管道一起添加到providers数组中,并将它们注入到
ColumnPipe的构造函数中这在ngx datatable
中是不可能的。您可以在源代码中看到这一点
但是,您可以创建另一个执行相同操作的管道:
无需使用注释将其设置为管道
,因为您不需要使用名称,这样您也不必将其添加到声明中
您的内部管道可能需要注入一些服务。在这种情况下,您需要将管道添加到providers数组,以及需要注入的管道,并将它们注入到ColumnPipe的构造函数中
谢谢@PierreDuc我希望他们很快就会允许这种方式:)谢谢@PierreDuc我希望他们很快就会允许这种方式:)
{{ birthday | customPipe1 | customPipe2 }}
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);
}
}