Reputation: 553
<ion-row *ngFor="let box of Boxes" >
<ion-col col-9>
<ion-item >
{{box}}
</ion-item>
</ion-col>
<ion-col col-3>
<ion-checkbox></ion-checkbox>
</ion-col>
</ion-row>
How to display item in alternate color ? alternate color for every row item.?
Upvotes: 7
Views: 10842
Reputation: 2007
Try this:
.html
<ion-row *ngFor="let box of Boxes">
<ion-col col-9>
<ion-item class="custom-bg">
{{box}}
</ion-item>
</ion-col>
<ion-col col-3>
<ion-checkbox></ion-checkbox>
</ion-col>
</ion-row>
.scss
.row-custom-bg:nth-of-type(even) {
background: green;
}
.row-custom-bg:nth-of-type(odd) {
background: blue;
}
I think it will be helpful..
Upvotes: 1
Reputation: 21681
Try this:
.html
<ion-row *ngFor="let box of Boxes; let i = index;">
<ion-col col-9>
<ion-item [ngClass]="(i % 2 == 0) ? 'odd' : 'even'">
{{box}}
</ion-item>
</ion-col>
<ion-col col-3>
<ion-checkbox></ion-checkbox>
</ion-col>
</ion-row>
.scss
.odd{
color: blue;
}
.even{
color: green;
}
Upvotes: 14
Reputation: 1754
You can use even odd properties of ngFor
<ion-row *ngFor="let box of Boxes; let odd=odd; let even=even;
[ngClass]="{ odd: oddStyleClass, even: evenStyleClass } >
Here oddStyleClass and evenStyleClass will define background color or any other style you want to apply
Upvotes: 0