0

I have a table value as a date.

<ng-container cdkColumnDef="lastModificationDate">
    <mat-header-cell *cdkHeaderCellDef fxFlex="30%">Last Modification Date</mat-header-cell>
    <mat-cell *cdkCellDef="let subgroup" fxFlex="30%">{{employee.lastModificationDate | date: 'dd MMM yy HH:mm'}}</mat-cell>
</ng-container>

This pipe is working for me good, but in some cases the date value is coming as null. In this case I want to populate it as "N/A".

so I need something like:

{{employee.lastModificationDate = null ? | date: 'dd MMM yy HH:mm' : 'N/A'}}

How can I do this optional operation with date pipe?

ferhen
  • 653
  • 1
  • 6
  • 16
Chris Garsonn
  • 717
  • 2
  • 18
  • 32
  • Does this answer your question? [Detecting an "invalid date" Date instance in JavaScript](https://stackoverflow.com/questions/1353684/detecting-an-invalid-date-date-instance-in-javascript) – A. Meshu Mar 31 '20 at 14:27
  • I think there is a pipe function that you can use on typescript. https://stackoverflow.com/questions/35159079/is-it-possible-to-use-a-pipe-in-the-code – Dimitrios Filippou Mar 31 '20 at 14:27
  • 1
    Why not just add two `mat-cell`s, each with a `*ngIf`? – Heretic Monkey Mar 31 '20 at 14:28

1 Answers1

0

Try the following syntax with the ternary operator:

{{ !!myDate ? (myDate | date:'dd MMM yy HH:mm') : 'N/A' }}

See this stackblitz for a demo

ConnorsFan
  • 70,558
  • 13
  • 122
  • 146