【问题标题】:Preventing an event from propagating in Angular防止事件在 Angular 中传播
【发布时间】:2020-05-06 23:52:56
【问题描述】:

我有一些这样的导航设置:

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

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

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

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

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

问题选项卡功能是这样做的:

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


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

【问题讨论】:

    标签: javascript angular typescript angular-router


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-11
      • 2020-09-09
      • 1970-01-01
      • 1970-01-01
      • 2021-07-10
      • 1970-01-01
      • 2011-01-04
      • 1970-01-01
      相关资源
      最近更新 更多