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?
Asked
Active
Viewed 127 times
0

MikeSpiris
- 73
- 6
-
2`[ngClass]="record.name === 'something' ? 'yourClass' : 'otherClass' "` – Roberto Zvjerković May 14 '18 at 11:51
-
https://stackoverflow.com/questions/34657821/ngif-and-ngfor-on-same-element-causing-error Can you refer here? – May 14 '18 at 11:53
3 Answers
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