I am trying to implement simple like and unlike functionality using one button. If a user already likes that card then it should have a filled red heart icon else just an outline heart icon. My problem is if I click the heart icon it changes all other card heart icons to red. I want to change only the currently clicked one. I tried to use property binding as shown in my code but it is still not working. I understand the problem is caused by the “isliked” variable but I am not sure how to specify only a specific card.
In my template I have the below code
<ion-card *ngFor="let ...>
<ion-row>
<ion-col>
<button ion-button icon-left clear small (click)=" (!current_user_liked || !isliked) ? processLike('like') : processLike( 'unlike')">
<ion-icon [name]="((current_user_liked || isliked) ? 'heart' : 'heart-outline'" </ion-icon>
</button>
</ion-col>
</ion-row>
</ion-card>
In my .ts file, I have the below code.
isliked:boolean = false;
processLike(action){
if(action == 'like'){
this.isliked = true;
}else if(action == 'unlike'){
this.isliked = false;
}
}
Cheers