Here, the code works fine:
form-focus element Angular way[
^]
import { Component, ViewChild, ElementRef } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
@ViewChild("name") nameField: ElementRef;
editName() {
this.nameField.nativeElement.focus();
}
}
Check out.