I have an HTML table and its rows are being generated by an ngFor loop. I need to add a class to these table cells if some criteria is met.
The issue is that that I need to check if the value of a property is empty AND see if the property even if the property even exists in the first place.
<tbody>
<tr *ngFor="let e of (modalData.compareData | filter: filterString)">
<td [class.success]="e.NewRuleVersionID === ''">{{ (e.OldRuleVersionID ? e.OldRuleVersionID : 'New') }}</td>
<td [class.success]="e.NewRuleVersionID === ''">{{ (e.OldOutcome ? e.OldOutcome : 'New') }}</td>
<td [class.danger]="e.OldRuleVersionID === ''">{{ (e.NewRuleVersionID ? e.NewRuleVersionID : 'Removed') }}</td>
<td [class.danger]="e.OldRuleVersionID === ''">{{ (e.NewOutcome ? e.NewOutcome : 'Removed') }}</td>
</tr>
</tbody>
In the above code, I am adding a class to those cells if the value doesn't exist. However, there are some records where that property doesn't exist at all. Can this be checked inline within the template so I can account for it?