On specific button click add a class

#1

I have a situation where i have multiple records and i used in that *ngFor loop , so per record there is one button And I am trying to do is onclick change background of button so that it looks alike it is clicked

<div class="main" *ngFor="let data of fetched_info; let i=index">
<ion-grid no-padding no-margin>
<ion-row no-padding no-margin class="row">
<ion-col col-4 no-padding no-margin> 
<button ion-button small icon-start color="secondary"
outline (click)="shortlist($event,data[i].username)" class="">
<ion-icon ios="ios-star-outline" md="md-star-outline"></ion-icon>
Shortlist
</button>
</ion-col>

</ion-row>
</ion-grid>
</div>

onclick of shortlist() function i want to make it happen

#2

u can use ngClass or ngStyle or ngIf and set a boolean or expression in the button tag such that when u click the button, u will toggle the boolean or expression to switch “on” the background of the button.

#3

yes i got it . Thankyou Its done.
Still if some one is looking for this kinda solution visit on this link
https://stackoverflow.com/questions/55278903/on-specific-button-click-add-a-class-in-ionic-3

#4

Sure. No mention. :slight_smile: