I have a grid where I need to apply conditional classes based on data from my .ts
file. I was able to accomplish this using the code snippet
myClassCondition = 5 < 6 ? 'bg-red' : null;
as shown below. However, I want to achieve a similar functionality with variables "col" and "rowData". This resulted in compilation errors because "col" and "rowData" are not defined in the .ts
file. How can I make this work?
<ng-template pTemplate="body" let-rowData>
<tr>
<td *ngFor="let col of myColumns" class="ui-resizable-column">
<span [ngClass]="myClassCondition"> {{rowData[col.field]}}</span>
</td>
</tr>
</ng-template>
The current setup is functioning without any issues.
myClassCondition = 5 < 6 ? 'bg-red' : null;
However, I would like to modify it to something like this:
myClassCondition = col.field == 'studentAge' && rowData.[col.field] < 6 ? 'bg-red' : null;
Even though I attempted the modification above, it did not produce the desired outcome.
myClassCondition : string = "col.field == 'studentAge' && rowData.[col.field] < 6 ? 'bg-red' : null";