I see many posts in how to set autofocus on an input filed in angularjs by creating a directive or HTML autofocus, Is there a quick and easy way to set focus in angular (angular 2, angular 4 etc)
In your html add #nameit
to get its reference in component code.
<input type="text" name="me" #nameit>
Then apply auto fouces into it.
@ViewChild('nameit') private elementRef: ElementRef;
public ngAfterViewInit(): void {
this.elementRef.nativeElement.focus();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With