防止事件在Angular中传播。

问题描述 投票:0回答:1

我有一些导航设置是这样的。

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

当用户点击 app-custom-start-cardonCustomParameters() 被激活,触发导航。

卡中还有一个按钮,打开外部链接。 当点击外部链接时,外部链接就会被打开,并触发了 onCustomParameters() 也会被发射。

比如卡里面有这个按钮。

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

问题标签的功能就是这样做的:

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


我想也许e.stopPropagation()可以做到这一点,但是不行。 有什么想法?

javascript angular typescript angular-router
1个回答
3
投票

试着通过 $eventissuesTab 在您的模板中。<button (click)="issuesTab($event)">,否则 e 除此以外,你在正确的轨道上与 e.stopPropagation().

© www.soinside.com 2019 - 2024. All rights reserved.