Here is a snippet of code I have that includes like and dislike buttons with font-awesome icons:
<ng-container *ngFor="let answer of question.answers">
<p class="answers">{{answer.text}} <i class="fa fa-hand-o-left" (click)="likeDislike($event,answer.id,'fa-thumbs-up')"></i></p>
</ng-container>
Additionally, there is a function:
likeDislike(event: any, answerId: string, haveClass: string) {
const hasClass = event.target.classList.contains(haveClass);
if (hasClass) {
this.renderer.removeClass(event.target, 'fa-thumbs-up');
this.renderer.addClass(event.target, 'fa-thumbs-down');
} else {
this.renderer.removeClass(event.target, 'fa-thumbs-down');
this.renderer.addClass(event.target, 'fa-thumbs-up');
}
}
I feel like this code could be improved by creating a directive. Can someone assist me with that?