Anup Malhan Anup Malhan - 4 years ago 295
AngularJS Question

Implementing ngClassEven ngClassOdd for angular 2

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.


<div *ngFor="#employee of employees; #index = index" [class.odd]="index%2==1" [class.even]="index%2==0" [class.selected]="employee === selectedEmployee">


.odd {
background-color: #f2f9ff;

.even {
background-color: #eceff3;

Answer Source

Another way,

<div *ngFor="#employee of employees; #index =index;#isOdd=odd;#isEven=even" 
    [class.selected]="employee === selectedEmployee"> 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download