Issue
I am trying to compare 2 dates to be able to display the data in a table. I am doing the following:
${this.dateToCompare.getTime()} > ${row.CreateDate.getTime()}
The problem is, CreateDate has a null value on some rows so the above is not working.
I have also tried this:
<div ng-if="${row.CreateDate!==null} && ${this.dateToCompare.getTime()} > ${row.CreateDate.getTime()}"
I need to check first if the row is null or not, but even when it is null, it is continuing after the && and when it hits the dateToCompare.getTime, it is throwing a syntax error because I am calling getTime on a null value.
Is it possible to tell ng-if to not run it if null and to skip that row? What is the best way to be able to fix this problem and be able to run the getTime() on it? Thank you
Solution
I had to create a function:
convToTime(date: Date) {
if (date !== null)
{
this.tDate = new Date(date.toString().substring(0,10));
return this.tDate.getTime();
}
}
and called it this way:
${this.convToTime(row.CreateDate)}
All working properly now and as needed.
Answered By - bottoslot
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.