Q:

ERROR TypeError: Cannot read property 'length' of undefined at Object.updateDirectives

I hava a angular 8 app. And if a certain component is loaded I get an error
Cannot read property 'length' of undefined
I googled a lot and doing some tutorials. But I can't figure how to handle the bug.
So if I load this component:
import { Component, OnInit } from '@angular/core';
import { HealthAPIService } from '../../shared/health-api/health-api.service';

import { DossierEntry } from '../../interfaces/dossier/dossier-entry.interface';

@Component({
  selector: 'app-dossier-correspondence',
  templateUrl: './dossier-correspondence.component.html',
})

export class DossierCorrespondenceComponent implements OnInit {
  allCorrespondence: Array<DossierEntry>;
  correspondenceEntries: Array<DossierEntry>;
  attachmentEntries: Array<DossierEntry>;
  message = '';
  emptyMessage = 'Geen correspondentie.';
  errorMessage = 'Er ging iets mis met de connectie. Probeer over enkele minuten nogmaals.';

  correspondenceLoaded = false;
  showingSingle = false;

  single: DossierEntry;

  constructor(private healthAPIService: HealthAPIService) {}

  handleCorrespondenceLoad(result) {
    if (result &&  result.length === 0) {
      this.message = this.emptyMessage;
      return;
    }
    this.allCorrespondence = result;
    this.attachmentEntries = [];
    this.correspondenceEntries = [];
    for (let entry of result) {
      switch (entry.type) {
        case 'correspondence': {
          this.correspondenceEntries.push(entry);
          break;
        }
        case 'attachments': {
          this.attachmentEntries.push(entry);
          break;
        }
        default: {
          console.log('Dossier correspondence heeft een invalide entry soort teruggegeven');
          break;
        }
      }
    }
  }

  gotoItem(index, type: string) {
    this.showingSingle = true;
    // this.single = this.allCorrespondence[index];
    switch (type) {
      case 'correspondence': {
        this.single = this.correspondenceEntries[index];
        break;
      }
      case 'attachments': {
        this.single = this.attachmentEntries[index];
        break;
      }
      default: {
        console.log('Er is op een ongeldige soort dossier entry geklikt');
        break;
      }
    }
  }

  goBack(event) {
    this.showingSingle = false;
  }

  ngOnInit() {
    this.healthAPIService.getDossierEntry('correspondence').subscribe(result => {
      console.log(result);
      this.handleCorrespondenceLoad(result), (this.correspondenceLoaded = true);
    }, msg => (this.message = this.errorMessage));
  }
}

Then I will get this error:
dossier-correspondence.component.html:6 ERROR TypeError: Cannot read property 'length' of undefined
    at Object.updateDirectives (dossier-correspondence.component.html:8)
    at Object.debugUpdateDirectives [as updateDirectives] (core.js:30537)
    at checkAndUpdateView (core.js:29933)
    at callViewAction (core.js:30174)
    at execComponentViewsAction (core.js:30116)
    at checkAndUpdateView (core.js:29939)
    at callViewAction (core.js:30174)
    at execEmbeddedViewsAction (core.js:30137)
    at checkAndUpdateView (core.js:29934)
    at callViewAction (core.js:30174)

On this line:
<app-is-loading *ngIf="!correspondenceLoaded" message="Correspondentie wordt geladen"></app-is-loading>

and this is the code of the app-is-loading component:
export class IsLoadingComponent implements OnInit {
  @Input() message: string;

  public text: string;

  constructor() {}

  ngOnInit() {
    this.text = this.message + '...';
  }
}

Thank you
Also now with the html file:
<app-vital10-page [noTopBar]="true">
<h2 class="section-header">Correspondentie</h2>

<p class="data-entry" *ngIf="!allCorrespondence">{{ message }}</p>

<app-is-loading *ngIf="!correspondenceLoaded" message="Correspondentie wordt geladen"></app-is-loading>

<div *ngIf="!showingSingle && correspondenceEntries.length > 0">
  <div class="main-row main-row-dossier">
    <section class="data-entry">
      <h3 class="dossier-header">Algemeen</h3>
      <table class="dossier-table">
        <thead class="dossier-tableheader">
          <tr>
            <th class="dossier-tablehead fixed-one-fifth">Datum</th>
            <th class="dossier-tablehead fixed-four-fifths">Onderwerp</th>
          </tr>
        </thead>
        <tbody class="dossier-tablebody">
          <tr class="dossier-correspondencerow" *ngFor="let entry of correspondenceEntries; let i = index" (click)="gotoItem(i, entry.type)">
            <td>{{ entry.date | date:"dd-MM-y" }}</td>
            <td>{{ entry.name }}</td>
          </tr>
        </tbody>
      </table>
    </section>
  </div>
</div>

<div *ngIf="!showingSingle && attachmentEntries.length > 0">
  <div class="main-row main-row-dossier">
    <section class="data-entry">
      <h3 class="dossier-header">Bijlage</h3>
      <table class="dossier-table">
        <thead class="dossier-tableheader">
        <tr>
          <th class="dossier-tablehead fixed-one-fifth">Datum</th>
          <th class="dossier-tablehead fixed-four-fifths">Onderwerp</th>
        </tr>
        </thead>
        <tbody class="dossier-tablebody">
        <tr class="dossier-correspondencerow" *ngFor="let entry of attachmentEntries; let i = index" (click)="gotoItem(i, entry.type)">
          <td>{{ entry.date | date:"dd-MM-y" }}</td>
          <td>{{ entry.name }}</td>
        </tr>
        </tbody>
      </table>
    </section>
  </div>
</div>

<app-dossier-correspondence-item
  [item]="single"
  (goBack)="goBack($event)"
  *ngIf="showingSingle">
</app-dossier-correspondence-item>
</app-vital10-page>

But then I wil get the error on this line:
<div *ngIf="!showingSingle && correspondenceEntries && correspondenceEntries.length > 0">

The html file looks now like this:
<app-vital10-page [noTopBar]="true">
<h2 class="section-header">Correspondentie</h2>

<p class="data-entry" *ngIf="!allCorrespondence">{{ message }}</p>

<app-is-loading *ngIf="!correspondenceLoaded" message="Correspondentie wordt geladen"></app-is-loading>

<div *ngIf="!showingSingle && correspondenceEntries && correspondenceEntries.length > 0">
  <div class="main-row main-row-dossier">
    <section class="data-entry">
      <h3 class="dossier-header">Algemeen</h3>
      <table class="dossier-table">
        <thead class="dossier-tableheader">
          <tr>
            <th class="dossier-tablehead fixed-one-fifth">Datum</th>
            <th class="dossier-tablehead fixed-four-fifths">Onderwerp</th>
          </tr>
        </thead>
        <tbody class="dossier-tablebody">
          <tr class="dossier-correspondencerow" *ngFor="let entry of correspondenceEntries; let i = index" (click)="gotoItem(i, entry.type)">
            <td>{{ entry.date | date:"dd-MM-y" }}</td>
            <td>{{ entry.name }}</td>
          </tr>
        </tbody>
      </table>
    </section>
  </div>
</div>

<div *ngIf="!showingSingle && attachmentEntries.length > 0">
  <div class="main-row main-row-dossier">
    <section class="data-entry">
      <h3 class="dossier-header">Bijlage</h3>
      <table class="dossier-table">
        <thead class="dossier-tableheader">
        <tr>
          <th class="dossier-tablehead fixed-one-fifth">Datum</th>
          <th class="dossier-tablehead fixed-four-fifths">Onderwerp</th>
        </tr>
        </thead>
        <tbody class="dossier-tablebody">
        <tr class="dossier-correspondencerow" *ngFor="let entry of attachmentEntries; let i = index" (click)="gotoItem(i, entry.type)">
          <td>{{ entry.date | date:"dd-MM-y" }}</td>
          <td>{{ entry.name }}</td>
        </tr>
        </tbody>
      </table>
    </section>
  </div>
</div>

<app-dossier-correspondence-item
  [item]="single"
  (goBack)="goBack($event)"
  *ngIf="showingSingle">
</app-dossier-correspondence-item>
</app-vital10-page>

With the error:
dossier-correspondence.component.html:8 ERROR TypeError: Cannot read property 'length' of undefined
    at Object.updateDirectives (dossier-correspondence.component.html:30)
    at Object.debugUpdateDirectives [as updateDirectives] (core.js:30537)
    at checkAndUpdateView (core.js:29933)
    at callViewAction (core.js:30174)
    at execComponentViewsAction (core.js:30116)
    at checkAndUpdateView (core.js:29939)
    at callViewAction (core.js:30174)
    at execEmbeddedViewsAction (core.js:30137)
    at checkAndUpdateView (core.js:29934)
    at callViewAction (core.js:30174)

A:

Try changing template fragment from
<app-is-loading *ngIf="!correspondenceLoaded" message="Correspondentie wordt geladen"></app-is-loading>

<div *ngIf="!showingSingle && correspondenceEntries.length > 0">

to 
<app-is-loading *ngIf="!correspondenceLoaded" message="Correspondentie wordt geladen"></app-is-loading>

<div *ngIf="!showingSingle && correspondenceEntries && correspondenceEntries.length > 0">

It seems you are trying to access correspondenceEntries.length when it's still not defined at all

