Reputation: 77
I'm very new to Angular technology and I'm facing a small issue in our code.
I need to adds a estimated arrival time to our current display (so obviously it's a Date type). The data is coming from the c# server, we everything else for the purpose of querying for the data is already built. It can be displayed like this below:
If I don't format the date, it will look like this: 0001-01-01T00:00:00
But as you can see, the issue is that when the arrival time reset in the server and then queried by the angular app, the minimum date time will be displayed on the UI. However, I'd like to make it display an empty space instead (or an empty string, whatever would makes sense here.)
Is there any way to detect this minimum date time value, and then instead print out an empty space or string (for example, like ' ')?
The html code is this:
<div>
<label>ETA</label>
<div>{{ eta | date: 'hh:mm a MM/dd' | default: ' ' }}</div>
</div>
The code from the component type script is, it's coming from an incident object we defined:
get eta(): Date {
return this.incident?.eta;
}
Upvotes: 0
Views: 2829
Reputation:
You could do something like this then:
HTML
<div>
<label>ETA</label>
<div *ngIf="!isMinimumDateTimeValue(eta)">{{ eta | date: 'hh:mm a MM/dd'}}</div>
<div *ngIf="isMinimumDateTimeValue(eta)"> </div>
</div>
TS
isMinimumDateTimeValue(eta: Date): Boolean {
return new Date(eta).getTime() === new Date('1/1/0001 12:00:00 AM').getTime();
}
Upvotes: 1