Home > OS >  Clickable icon inside div
Clickable icon inside div

Time:09-19

How to avoid triggering the div click event when clicking on ion-icon

<div(click)="goNext()">
    <ion-icon  name="close-circle-outline" size="large" (click)="dissmiss()"></ion-icon>
</div>

CodePudding user response:

On the dissmiss function you have to write your icon code logic. after performing you have to place event.stopPropagation() at the end of dissmiss function to stop event to trigger the parent events.

like this:

function dissmiss(event){
  // write code for icon close.
  event.stopPropagation();
}

the above code runs the logic that you written for icon close and the stopped immediately at this function and will not go to the parent node click.

CodePudding user response:

<div(click)="goNext()">
    <ion-icon  name="close-circle-outline" size="large" (click)="dissmiss($event)"></ion-icon>
</div>

And in the JS:

function dissmiss($event){
    $event.stopPropagation();
}
  • Related