I have a piece of code generated inside of an *ngFor, and a span with a (click) event that I can't figure why it does not fire when I click it. It does not print anything in the console.
Can this be because of the ngFor or ngIf ? I've tried everything I can think of...
My template looks like this (the relevant part):
<tbody>
<ng-container *ngIf="matches">
<tr *ngFor="let meci of matches">
<td>{{ meci.id }}</td>
<td>{{ meci.echipa1 }}</td>
<td>{{ meci.echipa2 }}</td>
<td>{{ meci.tip }}</td>
<td>{{ meci.pretBilet }}</td>
<td>{{ meci.nrLocuri }}</td>
<td>{{ meci.data }}</td>
<td class="ui center aligned">
<span class="fas fa-trash red icon"></span>
<span class="fas fa-edit teal icon" (click)="edit(meci)"></span>
</td>
</tr>
</ng-container>
</tbody>
And the component like this:
export class MatchesComponent implements OnInit {
matches: Meci[];
constructor(private service: MatchesService, private modalService: SuiModalService) { }
ngOnInit() {
this.service.getAll().subscribe(matches => this.matches = matches);
}
edit(meci: Meci) {
console.log('edit');
}
}
Ok, so after some more inspecting on the code, it seems that the problem was because of font awesome that it just commented the span and inserted a svg at runtime, so the (click) pointer was not available anymore. The solution was to wrap the span in a div and put the click event on the div like this:
<div class="icon-wrapper" (click)="edit(meci)">
<span class="fas fa-edit teal icon"></span>
</div>
Change the postion to relative and give some z-idex, issue can be because some other classes overlaping your span
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With