title: Undefined ViewChild in ngIf
body: <p>How can you focus on element inside ngIf?</p>
  
  <p>This ngIf is true when the page loads but it still gets an undefined error:</p>
  
  <pre><code>@ViewChild("currentDaySpentInput") currentDaySpentInput: ElementRef;  
  // ...
  &lt;div class="spending-input" *ngIf="!spentInputComplete"&gt;
      &lt;label&gt;How much did you spend today?&lt;/label&gt;
      &lt;input [(ngModel)]="currentDay.spent" (keyup)="onKey($event)" #currentDaySpentInput&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>focus element</p>
  
  <pre><code>ngOnOnit() {
      this.currentDaySpentInput.nativeElement.focus();
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>ERROR TypeError: Cannot read property 'nativeElement' of undefined
  </code></pre>
  
  <p>I tried using the setter suggested in this <a href="https://stackoverflow.com/questions/39366981/angular-2-viewchild-in-ngif">question</a> but it didn't work.</p>