Change the background color of a ion-item on click

Want to change the background color of an item once its clicked but its not working, here’s my css:

    --background-activated: red;

using ionic 5

you can use ngClass

for example in your html file you have

<ion-button (click)="toggleClickedItem()"   [ngClass]="{'itemClass': (this.itemClicked)}"> something to click </ion-button>

and in your .ts file

itemClicked: boolean = false;
toggleClickedItem() {
   this.itemClicked = !this.itemClicked;
1 Like

thanks, worked perfectly. do you know why this didnt work though? --background-activated: red;

I think those classes work in standard ionic components only

1 Like