title: Ionic pipe TypeError: Cannot read property 'toString' of undefined
body: <p>I have an Ionic 4 news reader app. Property <code>pubDate</code> of class <code>UutinenPage</code> is asynchronously being assigned a value <code>data.items[this.id].pubDate</code> in uutinen.page.ts. The value should look something like <code>2019-02-19 04:02:00</code>. I need to print out this string with <code>toLocaleDateString()</code> so that the result is 19.2.2019. I am getting the following error:</p>
  
  <pre><code>TypeError: Cannot read property 'toString' of undefined
  at JulkaisuaikaPipe.push../src/app/julkaisuaika.pipe.ts.JulkaisuaikaPipe.transform (julkaisuaika.pipe.ts:10)
  </code></pre>
  
  <p>uutinen.page.html:</p>
  
  <pre><code>&lt;ion-header&gt;
    &lt;ion-toolbar&gt;
      &lt;ion-title&gt;Yle Uutiset&lt;/ion-title&gt;
      &lt;ion-buttons slot="start"&gt;
        &lt;ion-button (click)="meneTakaisin()"&gt;
          &lt;ion-icon slot="start" name="arrow-back"&gt;&lt;/ion-icon&gt;
        &lt;/ion-button&gt;
      &lt;/ion-buttons&gt;
    &lt;/ion-toolbar&gt;
  &lt;/ion-header&gt;
  
  &lt;ion-content padding&gt;
    &lt;h1&gt;{{ uutinen?.title }}&lt;/h1&gt;
    &lt;p&gt;{{ uutinen?.description }}&lt;/p&gt;
    &lt;p&gt;&lt;b&gt;{{ uutinen?.categories[0] }}&lt;/b&gt; {{ pubDate | julkaisuaika }}&lt;/p&gt;
    &lt;img [src]="uutinen?.thumbnail"&gt;
    &lt;div [innerHTML]="uutinen?.content"&gt;&lt;/div&gt;
  &lt;/ion-content&gt;
  </code></pre>
  
  <p>uutinen.page.ts:</p>
  
  <pre><code>import { Pipe, PipeTransform } from '@angular/core';
  import { uutissyote } from './uutissyote.interface';
  
  @Pipe({
    name: 'julkaisuaika'
  })
  export class JulkaisuaikaPipe implements PipeTransform {
  
    transform(pubDate?: uutissyote): any {
      let pvm = new Date(pubDate.toString());
      return pvm.toLocaleDateString();
    }
  
  }
  </code></pre>
  
  <p>julkaisuaika.pipe.ts:</p>
  
  <pre><code>import { Pipe, PipeTransform } from '@angular/core';
  import { uutissyote } from './uutissyote.interface';
  
  @Pipe({
    name: 'julkaisuaika'
  })
  export class JulkaisuaikaPipe implements PipeTransform {
  
    transform(pubDate?: uutissyote): any {
      let pvm = new Date(pubDate.toString());
      return pvm.toLocaleDateString();
    }
  
  }
  </code></pre>