title: Why am I receiving "ERROR TypeError: Cannot read property 'length' of undefined" on a defined array?
body: <p>I defined, initialized(TWICE) my array, yet i am getting "ERROR TypeError: Cannot read property 'length' of undefined" at runtime.</p>
  
  <p>I already tried to check if the array was defined as you can see in my code, still angular is just trolling me.
  I already tried all solutions like changing the sintax to "filesToUpload &amp;&amp; filesToUpload?.length > 0" or any possible combination, however Angular is just not working properly imo.</p>
  
  <p>component.html file</p>
  
  <pre><code>&lt;ng-container *ngIf="undefined !== filesToUpload &amp;&amp; filesToUpload.length &gt; 0"&gt;
    &lt;button (click)='uploadImages()' 
             class="btn btn-success" 
             type="button"&gt;
            &lt;i class="fas fa-upload"&gt;&lt;/i&gt;Upload
    &lt;/button&gt;
  
    &lt;button (click)='cancelUpdate()' 
            class="btn btn-danger" 
            type="button"&gt;Cancel&lt;/button&gt;
  &lt;/ng-container&gt;
  </code></pre>
  
  <p>This is my component.ts file</p>
  
  <pre><code>export class ImageGalleryUploadComponent implements OnInit 
  {
    filesToUpload: File[] = [];
    ngOnInit() {
      this.filesToUpload = []
    }
  }
  </code></pre>
  
  <p>is this an angular bug? or has something to do with component lifecycle?</p>