Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using date pipe in a conditional expression - Angular 2

Tags:

angular

With the follow expression I'm expecting for Angular to interpolate a date (if not null) through the date pipe, but I get the proceeding error.

{{charge.offenseDate ? charge.offenseDate | date : 'No date'}}  EXCEPTION: Error: Uncaught (in promise): Template parse errors: Parser Error: Conditional expression {{charge.offenseDate ? charge.offenseDate | date : 'No Date' }} requires all 3 expressions at the end of the expression 

Is what I'm expecting possible, or just a...pipe dream :)

like image 682
sharpmachine Avatar asked Jul 06 '16 02:07

sharpmachine


2 Answers

Just wrap it with ()

{{charge.offenseDate ? (charge.offenseDate | date) : 'No date'}} 
like image 131
Günter Zöchbauer Avatar answered Sep 21 '22 22:09

Günter Zöchbauer


For more than one pipe u can use

text="{{ item.COURSE_REGED == 0 ?  ('EDU_COURSE_SIGNUP'| translate ) +(item.COURSE_COST | number)+ ('PUP_CURRENCY_NAME' | translate)   : ('EDU_COURSE_SIGNED_UP'| translate) }}" 
like image 44
amirnader afshari Avatar answered Sep 19 '22 22:09

amirnader afshari