0

I have a property that I am displaying on an angular template which may or may not be a date. If it is a date, I would like to format it but if it's not, I just want to show the value.

This is what I have tried based on researching and it only worked for dates, for everything else it was blank:

<td>{{key | date: 'MM/dd/yyyy' || key}}</td>

I could add a Boolean property:

<td *ngIf="isDate">{{key | date: 'MM/dd/yyyy'}}</td>
<td *ngIf="!isDate">{{key}}</td>

but is there a way to do this directly in the template?

cooper
  • 417
  • 1
  • 10
  • 20

1 Answers1

0

You would need to check the value on the typescript side first to see (for example) if the value contains a "/" and set another variable to true or false if it is indeed a date or not.

Andrew Howard
  • 2,818
  • 5
  • 33
  • 59