if i click item i need to add class name and if click same item need to remove the class for ngFor loop
<ion-item *ngFor="let x of statementresponse;let i=index" class="cust_delay delay" [ngClass]="{'active': selectedItem == x}" (click)="listClick($event, x)" >
</ion-item>
selectedItem:any;
listClick(event, newValue) {
console.log(newValue);
this.selectedItem = !newValue;.
}
Try the following:
HTML
Typescript:
StackBlitz
One of the ways you can do this is having your items have an "active" property, something like this:
And inside the template represent them like this:
And finally the toggleClass() method just toggles the active state of the clicked item:
Example
You can store a boolean for that value somewhere. like in the object itself and then use
<ion-item [class.myClass]="item.myClass"></ion-item>
item.myClass
being the booleanand on click flip that value
item["myClass"] = !item["myClass"]