<!--snippet from template file-->
<custom-component
... other properties
(mousedown)="onMouseDown()"
</custom-component>
@Component({
//selector and templateURL
})
class ContainerComponent{
onMouseDown(){
//get the reference to the custom component here
}
}
因此,我的模板文件中有多个自定义组件指向相同的mousedown
事件,如何获取对customComponent的引用。我想要对组件的真正引用而不是本机元素,我希望它将它与@ViewChild()事物进行比较。
答案 0 :(得分:0)
import { Component,ViewChild} from '@angular/core';
<!--snippet from template file-->
<custom-component #start
... other properties
(mousedown)="onMouseDown()"
</custom-component>
@Component({
//selector and templateURL
})
class ContainerComponent{
@ViewChild('start') start;
onMouseDown(){
//this.start holds the reference
//get the reference to the custom component here
}
}