How can I get the host element reference in angular 2? In my case I want to know that in my component if it has a focus or not. Is it possible?
Best Regards!
How can I get the host element reference in angular 2? In my case I want to know that in my component if it has a focus or not. Is it possible?
Best Regards!
You get the host element reference using
class MyComponent { constructor(private elRef:ElementRef) { console.log(this.elRef.nativeElement); } }
You can also subscribe to the focus
event
class MyComponent { @HostBinding() tabindex = 0; @HostListener('focus', ['$event']) onFocus(event) { console.log(event); } }