Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 组件上的角度单击事件将内部元素发送为目标_Javascript_Angular - Fatal编程技术网

Javascript 组件上的角度单击事件将内部元素发送为目标

Javascript 组件上的角度单击事件将内部元素发送为目标,javascript,angular,Javascript,Angular,我在角度组件上有一个单击事件: import { Component } from "@angular/core"; @Component({ template: ` <hello (click)="onClick($event)"></hello> ` }) export class AppComponent { onClick(e) { alert("Click on TAG: "

我在角度组件上有一个单击事件:

import { Component } from "@angular/core";

@Component({
  template: `
    <hello (click)="onClick($event)"></hello>
  `
})
export class AppComponent {
  onClick(e) {
    alert("Click on TAG: " + e.target.tagName);
  }
}
从“@angular/core”导入{Component};
@组成部分({
模板:`
`
})
导出类AppComponent{
onClick(e){
警报(“单击标记:+e.target.tagName”);
}
}
请参阅在线演示:


为什么
event.target
是组件的内部元素而不是组件本身?

这是因为
event.target
指触发事件的元素

我想您正在查找
event.currentTarget
,它指的是事件侦听器附加到的元素