I´m currently trying to set the cursors focus on a specific input field, which is just displayed when the surrounding ngIf is true.
The html code looks something like this:
<div>
<button (click)="showFirst = !showFirst">Toogle</button>
<div *ngIf="showFirst">
<!-- Some content -->
</div>
<div *ngIf="!showFirst">
<input type="text" #myInput>
</div>
</div>
In my components JS I´m trying to get the ElementRef but it returns undefined all the time because I try to fetch it before it was initialized.
So the qustion is:
How is it possible to set the focus on the input field after showFirst becomes false and the input gets visible?