I have two input elements that are shown under *ngIf
conditions.
<input type="text" id="textInput" *ngIf="showTextInput">
<input type="number" id="numericInput" *ngIf="showNumericInput">
<button (click)="editButtonClicked($event)">
Clicking on the button should set focus to the appropriate input element.
editButtonClicked(event) {
// Focus on either #textInput or #numericInput element
}
I've looked into ElementRef to give the html input elements tags like #textInput
and then define them on the class for example:
@ViewChild('textInput') textInput: ElementRef;
...but apparently this does not work on elements that have *ngIf
conditionals.
How can I focus on an input element, onClick of a button?