Angular conditional using built in pipes

2019-08-30 07:25发布

问题:

Hi I have a similar problem posted in here: Angular 2 Pipe under condition

But instead of creating custom pipes, I would like to use the built in ones.

Say I have an array like this:

[{value: '1', type:'number'},{value:'1/18/2018', type: 'date'}]

and would like to use it like this assuming I'm looping through it:

{{ arr.type ? (arr.value | arr.type) : (arr.value)}}

It gives me an error of Parser Error: Missing expected )

回答1:

You can do it like this:

public myArr = [this.numberPipe(1), this.datePipe('1/18/2018', 'yyyy-MM-dd')];

constructor(private numberPipe: NumberPipe, private datePipe: DatePipe) {}

And then in template simply loop the values and display it with {{arr}}.



标签: angular