比方說,我有一個pipeVar,它可以是任何管道,例如:數字,大小寫,customPipe等有沒有一種方法來動態評估/使用角度(角度2+)管道?
有沒有一種簡單的方法只是調用類似
{{ myVal | pipeVar }}
或一些特殊的語法像
{{ myVal | #pipeVar }}
?
我到目前爲止發現的最接近的是Dynamic pipe in Angular 2
比方說,我有一個pipeVar,它可以是任何管道,例如:數字,大小寫,customPipe等有沒有一種方法來動態評估/使用角度(角度2+)管道?
有沒有一種簡單的方法只是調用類似
{{ myVal | pipeVar }}
或一些特殊的語法像
{{ myVal | #pipeVar }}
?
我到目前爲止發現的最接近的是Dynamic pipe in Angular 2
我有更新plunkr plunkr link
變化動態pipe.ts這樣
const dynamicPipe = "";
//i have give one simple logic for example if your dynamic pipe is like
this.dynamicPipe = ['number','uppercase','customPipe']; //pipe,pipe1 ... pipeN
//now create a one variable like 'number' | 'uppercase' | 'customPipe'
for (let i=0;i<this.dynamicPipe.length;i++){
dynamicPipe = dynamicPipe + " | "+this.dynamicPipe[i];
}
@Component({
selector: 'dynamic-comp',
template: '{{ data ' + dynamicPipe + '}}'
})
我明白了。感謝您指出我們可以讓編譯器關心多管支持。我還沒有測試過AOT的解決方案,你知道它是否可以與AOT協同工作? – techguy2000
什麼是AOT?我不知道AOT。 –
提前編譯。 yurzui提到它不適用於AOT。雖然我還沒有試過 – techguy2000
入住這https://開頭plnkr。 co/edit/Vz88zzWwzPbqgIpMinPp?p =預覽 – yurzui
@yurzui感謝闖入者。我正在考慮類似的實施。但是具有額外參數的管道也需要支持。另外,我認爲我需要支持多個管道纔是理想的,比如'passThrough:[actualPipes]' – techguy2000
請檢查這個plunkr https://plnkr.co/edit/xX1klYoaGMq1O2TJzu8w?p=preview –