I’m trying to change the color of a single button when clicked, then when clicked again to undo the color change or change it back to its original color.
Similar to the docs as you can see at the bottom, change color: https://beta.ionicframework.com/docs/api/button
At the moment, I’m rendering multiple buttons through ngFor on the template side.
<ion-col class=“friend-col” *ngFor=“let friend of friendOptions”>
<ion-button [ngClass]="{‘my-css-class’: active === ‘friend’}" (click)=“updateActive(‘friend’)”>
{{friend}}
< /ion-button>
< /ion-col>
Styling:
.my-css-class{
–background: #488aff !important;
}
The active button when clicked will have taken on the css class that makes it active. On the component side, I have it set up like this:
updateActive(friend){
this.active = friend;
}
My issue is when a single button is clicked, it changes the color of all them instead of just one. Unsure what to do because this ngClass is set to all of the buttons.