Angular 2 Pipe under condition

Daniel Kucal picture Daniel Kucal · Apr 29, 2016 · Viewed 43.6k times · Source

Is it possible in Angular 2 to apply a pipe under condition? I would like to do something like:

{{ variable.text | (variable.value ? SomePipe : OtherPipe) }}

If not, what is the preferred way to achieve this effect?

Answer

Günter Zöchbauer picture Günter Zöchbauer · Apr 29, 2016

You need to change the syntax a bit:

{{variable.value ? (variable.text | SomePipe) : (variable.text | pipe2)}}

Plunker example