admin管理员组文章数量:1356716
I have a click event on an Angular ponent:
import { Component } from "@angular/core";
@Component({
template: `
<hello (click)="onClick($event)"></hello>
`
})
export class AppComponent {
onClick(e) {
alert("Click on TAG: " + e.target.tagName);
}
}
See demo online: ponent.ts
Why is event.target
an inner element of the ponent and not the ponent itself?
I have a click event on an Angular ponent:
import { Component } from "@angular/core";
@Component({
template: `
<hello (click)="onClick($event)"></hello>
`
})
export class AppComponent {
onClick(e) {
alert("Click on TAG: " + e.target.tagName);
}
}
See demo online: https://stackblitz./edit/angular-ivy-zxmsnc?file=src%2Fapp%2Fapp.ponent.ts
Why is event.target
an inner element of the ponent and not the ponent itself?
1 Answer
Reset to default 12That's because event.target
refers to the element that triggered the event.
I think you're looking for event.currentTarget
which refers to the element that the event listener is attached to.
本文标签: javascriptAngular click event on component send inner element as targetStack Overflow
版权声明:本文标题:javascript - Angular click event on component send inner element as target - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744040966a2580655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论