阻止事件在 Angular 中传播

Preventing an event from propagating in Angular

我有这样的导航设置:

    <a (click)="onCustomParameters()">
        <app-custom-start-card></app-custom-start-card>
    </a>

当用户点击 app-custom-start-card 时,onCustomParameters() 被触发,触发导航。

卡片中还有一个按钮可以打开外部link。单击时打开外部 link,同时触发 onCustomParameters()

例如卡片里面有这个按钮:

<button (click)="issuesTab()">Issues</button> Github Repository.

问题选项卡功能执行此操作:

  issuesTab(e:any) {
    e.stopPropagation()
    window.open(ISSUES_URL, '_blank');
  }


我想也许 e.stopPropagation() 可以解决问题,但没有 bieno。想法?

尝试在您的模板中将 $event 传递给 issuesTab<button (click)="issuesTab($event)">,否则 e 将是未定义的。除此之外,您 e.stopPropagation() 走在正确的轨道上。