title: Angular 6: Cannot set property of undefined
body: <p>I have a weird error, at my application the prevents me from moving forward.
  I have a variable of type <code>any[]</code>, which using me as a data source of a table:</p>
  
  <pre><code>&lt;table mat-table  [dataSource]="EcoSummaryList"&gt;
  </code></pre>
  
  <p>the variable is initialized into an empty array. But when I'm trying even to assign something into the array, I'm getting the following error:</p>
  
  <blockquote>
    <p>core.js:12632 ERROR TypeError: Cannot set property 'EcoSummaryList' of
    undefined at
    push../src/app/eco-summary/eco-summary.component.ts.EcoSummaryComponent.OnSummaryLoad</p>
  </blockquote>
  
  <p>Here's the relevant code:</p>
  
  <pre><code>public EcoSummaryList: any[] = [];
  
  OnSummaryLoad(data: any) {
    this.EcoSummaryList = [];
    console.log(data);
  
    if (data == undefined || data == null) return;
    this.EcoSummaryList = data;
  
  }
  </code></pre>
  
  <p>The data object is all right, and the data is coming all right and it used to work in the past. </p>
  
  <p>I tried to look at other posts to find the answer without any success and I also tried to initialize the array at the constructor, at <code>ngOnInit</code> and to create the var as from type <code>Array&lt;MyClass&gt;</code> and then call <code>new Array&lt;MyClass&gt;();</code></p>
  
  <p>nothing seems to work, any advice? </p>
  
  <p>update: even when I comment out the <code>&lt;table&gt;</code> and just assigned <code>[]</code> into the var I'm still getting the same error.</p>