简体   繁体   English

使父 div 可点击,但子图标除外

[英]make a parent div clickable except for a child icon

 <div [ngClass]="{ 'template-row': ,isExpandable: 'folder-row': isExpandable }" class="label-with-icons clickable" (click)="expanderClicked()" (click)="itemSelected()" > <i *ngIf="isExpandable" [ngClass]="getArrowIconClass()"></i><i [ngClass]="getIconClass()"></i> <span *ngIf="id" class="name ">{{ name }}</span> <span *ngIf="!id" class="name">{{ name }}</span> <i *ngIf="!isExpandable" class="io-icon-trash clickable" id="delete" (click)="deleteTemplate()"></i> </div>

I want the entire div to be clickable but not the icon with id= delete.我希望整个 div 都是可点击的,但不是 id=delete 的图标。 I want to have a different click event on that I dont use jquery, i work with TS我想有一个不同的点击事件,我不使用 jquery,我使用 TS

You can stop the event to propagate up in the DOM tree with event.stopPropagation() :您可以使用event.stopPropagation()阻止事件在 DOM 树中向上传播:

(click)="deleteTemplate($event)"></i>

deleteTemplate(e: Event) {
    e.stopPropagation(); // <----event won't travel up 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM