角度点击事件未触发

rar*_*ude 4 events click onclick angular

我在 *ngFor 内部生成了一段代码,以及一个带有(单击)事件的跨度,我无法弄清楚为什么当我单击它时它不会触发。它不会在控制台中打印任何内容。

这可能是因为 ngFor 或 ngIf 吗?我已经尝试了所有我能想到的...

我的模板如下所示(相关部分):

<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>
Run Code Online (Sandbox Code Playgroud)

组件是这样的:

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

}
Run Code Online (Sandbox Code Playgroud)

rar*_*ude 5

好吧,在对代码进行更多检查后,问题似乎是由于 font Awesome 导致它只是注释了跨度并在运行时插入了 svg,因此(单击)指针不再可用。解决方案是将 span 包装在 div 中,并将单击事件放在 div 上,如下所示:

<div class="icon-wrapper" (click)="edit(meci)">
   <span class="fas fa-edit teal icon"></span>
</div>
Run Code Online (Sandbox Code Playgroud)

使用浏览器中的开发人员工具进行检查