I tried to implement ng-class-even and ng-class-odd ( from angular 1) type behaviour in angular 2 application.
I have written the code below and its working fine, I want to know if there is any other way of doing this.
HTML
<div *ngFor="#employee of employees; #index = index" [class.odd]="index%2==1" [class.even]="index%2==0" [class.selected]="employee === selectedEmployee">
<p>{{employee.name}}</p>
</div>
CSS
.odd {
background-color: #f2f9ff;
}
.even {
background-color: #eceff3;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…