Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular click event not firing

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');
  }

}
like image 504
rares_dude Avatar asked Oct 14 '25 20:10

rares_dude


2 Answers

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>

Inspect with developer tools from browser

like image 182
rares_dude Avatar answered Oct 17 '25 13:10

rares_dude


Change the postion to relative and give some z-idex, issue can be because some other classes overlaping your span

like image 31
Pran R.V Avatar answered Oct 17 '25 11:10

Pran R.V



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!