Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 how to handle value of date pipe is null

I have template using date pipe like this

{{value | date: 'dd/MM/yyyy'}}

this value is null

How to handle this if my value null i got string 'object not match'?

like image 986
Youngz ie Avatar asked Feb 08 '17 09:02

Youngz ie


People also ask

What angular pipe can we use to show a date with a specific format?

Angular date pipe used to format dates in angular according to the given date formats,timezone and country locale information. Using date pipe, we can convert a date object, a number (milliseconds from UTC) or an ISO date strings according to given predefined angular date formats or custom angular date formats.

How do I change date format in DatePipe?

You have to pass the locale string as an argument to DatePipe. var ddMMyyyy = this. datePipe. transform(new Date(),"dd-MM-yyyy");


2 Answers

{{ (value !== null) ? (value | date: 'dd/MM/yyyy') : "" }}
like image 189
Bharat Chauhan Avatar answered Nov 19 '22 06:11

Bharat Chauhan


Checked with Angular 4.2.4

{{(value | date:'dd/MM/yyyy') || 'n/a' }}
like image 18
Yurii Bratchuk Avatar answered Nov 19 '22 08:11

Yurii Bratchuk