title: ERROR TypeError: Cannot read property 'length' of undefined angular 4 (NOT DUPLICATE)
body: <p>I am getting the following error <code>LeaderBoardComponent.html:27 ERROR TypeError: Cannot read property 'length' of undefined</code></p>
  
  <p>The error is in the HTML:</p>
  
  <p><code>&lt;div *ngIf="leaderBoardTableData.length &gt; 0"&gt;</code></p>
  
  <p>In the component I have:</p>
  
  <pre><code>export class LeaderBoardComponent implements OnInit {
      leaderBoardTableData: Array&lt;LeaderBoardModel&gt;;
      constructor(private leaderBoardService: LeaderBoardService) { }
  
      ngOnInit() {
          this.subscribeLeaderBoardDataFromStore();
      }
  
      subscribeLeaderBoardDataFromStore() {
          this.leaderBoardService.getLeaderBoard()
              .skipWhile((data) =&gt; { return _.isEmpty(data) })
              .subscribe((data) =&gt; {
                  if (!_.isEmpty(data)) {
                      this.leaderBoardTableData = [data];
                  }
              });
      }
  </code></pre>
  
  <p>and the service:</p>
  
  <pre><code>getLeaderBoard(): Observable&lt;LeaderBoardModel&gt; {
          return this.httpUtil.get(this.appConstants.END_POINT_LEADERBOARD)
              .map(response =&gt; &lt;LeaderBoardModel&gt;response.json());
      }
  </code></pre>
  
  <p>When I tried to do the following:</p>
  
  <p><code>hello 1 &lt;div *ngIf="leaderBoardTableData.length &gt; 0"&gt; hello 2</code>
  Only <code>hello 1</code> printed and I got the error.</p>