I have a GUI with many dynamically generated inputs.
I can assign the inputs dynamically generated id's like so:
<ul>
<li *ngFor="#item of items" >
<mat-form-field>
<input type=number attr.id={{item.name}}}
</mat-form-field>
</li>
</ul>
I wish to be able to set the focus on a particular input with a dynamic name. Is this possible?
Because the id's are dynamically generated we cannot use the @viewchild approach like so:
@ViewChild('usernameField') usernameField: ElementRef;
ngAfterViewInit() {
this.usernameField.nativeElement.focus();
}
There is some mention of a focus method, and FocusOptions in the material documentation, but no examples:
document.getElementById(myDynamicId).focus()?