Good day! Currently, I am developing a webpage using Angular and aiming to incorporate a feature that enables users to post comments and mark them with a star if desired. Below is the snippet of the HTML
section:
<ul>
<li class="realitive" *ngFor="let comment of comments">
{{ comment }}
<nb-icon pack="font-awesome" class="fa-star absulute" [ngClass]="{ 'fas': isFavorite,' far': !isFavorite}" (click)="onClick()"></nb-icon>
</li>
</ul>
Additionally, here's the behind-the-scenes logic:
comments: string[] = [];
@Input("isFavorite") isFavorite: boolean;
@Output("change") change= new EventEmitter();
onClick() {
this.isFavorite = !this.isFavorite;
this.change.emit({ newValue: this.isFavorite });
}
addComment() {
this.dialogService.open(CommentComponent)
.onClose.subscribe(comment => comment && this.comments.push(comment));
}
Please note: The dialogServis component used in this code can be found at Nebular
The current implementation works well, but upon testing with multiple comments, clicking on a star activates both simultaneously. How can I modify the code to allow separate star activation for each individual comment?