ionic2 ion-list with a button both having (click) event

自古美人都是妖i 提交于 2019-11-28 11:43:14

You can solve this issue by using event.stopPropagation();.

Please take a look at this plunker.

like you can see there, I also send the $event object to both methods

<ion-list>
    <ion-item *ngFor="let item of items" (click)="open($event, item)">
        {{ item }}
        <ion-icon (click)="download($event, item)" item-right name="download"></ion-icon>
    </ion-item>
</ion-list>

And then I use that information to stop the propagation of the event, so only the download method will be executed when clicking the download icon

  public open(event, item) {
    event.stopPropagation();
    alert('Open ' + item);
  }

  public download(event, item) {
    event.stopPropagation();
    alert('Download ' + item);
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!