简体   繁体   中英

how can i change color buttons on click ionic 2 angular

I tried to change the color of the button i click, but it change all the colors of the buttons of the list

this is my code :

 ecardGroup(groupe) { if(this.hexColor === '#000000') { this.hexColor = '#dddddd' } else { this.hexColor = '#000000' } } 
  <ion-col col-9 class="sildes"> <ion-slides slidesPerView="{{nbPerPage}}" spaceBetween="5"> <ion-slide *ngFor="let slide of lesEboxs; let i = index"> <button ion-button block (click)="ecardGroup(slide)" class="currentGroup" [style.background-color]="hexColor"> <ion-icon class="warning" name="star" *ngIf="slide.nom_gr == 'Pro'"></ion-icon> {{slide.nom_gr}} </button> </ion-slide> </ion-slides> </ion-col> 

在您的课程上创建一个slideClicked属性,并像这样更改模板:

<button ion-button block [style.background-color]="(slide === this.slideClicked) ? '#000000' : '#dddddd'" (click)="this.slideClicked = slide" class="currentGroup">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM