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?


You need to change the syntax a bit:

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

Plunker example


You could also use ngIf

<ng-container *ngIf="variable.value; else elseBlock">{{ variable.text | SomePipe }}</ng-container>
<ng-template #elseBlock>{{ variable.text | OtherPipe }}</ng-template>

I find it useful in case the line becomes too long.