Below is an example of a dynamically generated textbox:
<tr *ngFor="let item of data; let in=index">
<td>
<input #unitNumber type="text" name="workPerformed-workcode-{{in}}" [(ngModel)] = "item.unitnumber" >
</td>
<td> <!-- Search option is given to choose the unit number----></td>
</tr>
A search option is provided to select the unit number. When a unit number is chosen, the corresponding textbox will be focused using ViewChild.
This is my attempt:
@ViewChildren('unitNumber') enteredUnitNumbers;
// To initiate searching, I utilized a material dialog box
const dialogRef = this.dialog.open(SearchEquipmentComponent, dialogConfig);
dialogRef.afterClosed().subscribe(
<!-- HERE I NEED TO DO THE FOCUS ON PARTICULAR TEXTBOX ---->
// console.log(this.enteredUnitNumbers.toArray().map(x => x))
});
The console log above shows undefined. My objective is to focus on the specific unit number textbox once the dialog box is closed.
Please provide solutions.