I'm looking to display a date value in my html (with a pipe expression), but only if that date exists.
If that field comes back as null, then I'm replacing it with N/A in my controller js code.
I think this should be simple, but I'm having a some trouble getting it to work.
This currently displays the date, or just blank if date is null.
<div>
<label>
{{ctrl.data.myDate | stringToDate:'yyyy-MM-dd'}}
</label>
</div>
I'm trying :
<div>
<label>
<span ng-if="ctrl.data.myDate!='N/A'">
{{ctrl.data.myDate | stringToDate:'yyyy-MM-dd'}}
</span>
</label>
<label>
<span ng-if="ctrl.data.myDate=='N/A'">
N/A
</span>
</label>
</div>
However, it's displaying null when the date is N/A.
This works, but without the pipe expression - however, I NEED to pipe the date string properly:
<span>{{vm.data.myDate==='N/A' ? "N/A" : vm.data.myDate }}</span>
UPDATE
I'm trying a different approach where I can use the Angular $filter provider. So if myDate is NOT NULL, I can format the date in my js controller :
vm.data.myDate = $filter('date')(new Date(data[0].closeDate), 'yyyy-MM-dd');
|). Two bars (||) is the OR operatorctrl.data.myDateequal to the string "N/A" before it runs through the date filter?nullin.myDate. Ifnullthen I replace withN/A. Please see my updated post with ternary expression.