typescript – Angular 2获取主机元素引用

前端之家收集整理的这篇文章主要介绍了typescript – Angular 2获取主机元素引用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在角度2中获取主机元素参考?在我的情况下,我想知道在我的组件中是否有焦点。可能吗?

最好的祝福!

您可以使用获取主机元素引用
class MyComponent {
  constructor(private elRef:ElementRef) {
    console.log(this.elRef.nativeElement);
  }
}

您还可以订阅焦点事件

class MyComponent {
  @HostBinding() tabindex = 0;
  @HostListener('focus',['$event'])
  onFocus(event) {
    console.log(event);
  }
}
原文链接:https://www.f2er.com/angularjs/143831.html

猜你在找的Angularjs相关文章