0

I am using *ngFor to list table data: *ngFor="let record of records", and I want to set custom css class to record based on some conditions, f.e. if record.name === something. Is this possible?

MikeSpiris
  • 73
  • 6

3 Answers3

2

Yes, you on [ngClass] to achieve this, for example:

<div [ngClass]="{'record': record.name === 'something' }" *ngFor="let record of records">
Chris
  • 4,672
  • 13
  • 52
  • 93
0

you can try this way :

  <ul class="r " *ngFor="let posto of posti">
    <li [ngClass]="posto.id === something ? NewClass : oldclass" >
     {{Something.id}} 
    </li>
  </ul>
Abhishek Ekaanth
  • 2,511
  • 2
  • 19
  • 40
0
<tr *ngFor="let record of records">    
  <td [ngClass]="record.name === 'something' ? 'classForSomething' : 'classForOthers' ">{{record.name}}</td> 
</tr>
M Rameez
  • 189
  • 1
  • 3
  • 10