In angular 2 when #elementReference is used with *ngIf the reference to the element remains undefined
even after *ngIf expression evaluates to true
. In following example the input's
value will not be shown.
<input *ngIf="true" type="text" #myRef (input)="a = 'b';" class="form-control input-lg">
<pre> {{ myRef?.value }} </pre>
But however following will work (surprised me).
<div *ngIf="true">
<input type="text" #myRef (input)="a = 'b';" class="form-control input-lg">
<pre> {{ myRef?.value }} </pre>
</div>
My question is how do I get the #reference to the element from anywhere in the template when used with *ngIf like directives.