buc*_*aci 43 typescript angular
如何在角度2中获取主机元素参考?在我的情况下,我想知道在我的组件中是否有焦点.可能吗?
最好的祝福!
Gün*_*uer 80
您将获得主机元素引用
class MyComponent {
constructor(private elRef:ElementRef) {
console.log(this.elRef.nativeElement);
}
}
Run Code Online (Sandbox Code Playgroud)
您也可以订阅该focus活动
class MyComponent {
@HostBinding() tabindex = 0;
@HostListener('focus', ['$event'])
onFocus(event) {
console.log(event);
}
}
Run Code Online (Sandbox Code Playgroud)
使用ViewContainerRef表示一个容器,其中一个或多个视图可以附加到组件。
constructor(private readonly viewRef: ViewContainerRef) {
console.log(this.viewRef.element.nativeElement);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27200 次 |
| 最近记录: |