import { Directive, ElementRef, OnInit, AfterViewInit } from '@angular/core';
@Directive({
selector: '[appAutofocus]'
})
export class AutofocusDirective implements OnInit, AfterViewInit {
constructor(private elementRef: ElementRef) { }
ngOnInit(): void {
this.elementRef.nativeElement.focus()
}
ngAfterViewInit(): void {
setTimeout(() => {
this.elementRef.nativeElement.focus();
}, 10);
}
}
Created
August 21, 2022 20:26
-
-
Save raviagheda/ab9e5f4e501ff4aa17350fc8d353ab67 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment