Ionic 4 Changing color of all buttons instead of single when clicked , toggle

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:

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’)”>
< /ion-button>
< /ion-col>


–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){ = 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.


You’re passing in the string ‘friend’ in to the updateActive(). So every button you click will be setting the variable friend=‘friend’.

should be

Thanks, that worked,

I just have two more questions:

Is there a way to toggle the color to change back? When clicked to revert back to its previous color.

And is there a way to click another button to change color without the other button changing back?