title: Angular 7: TypeError: Cannot read properties of undefined (reading 'substr')
body: <p>I have and angular 7.1.4 app that compiles successfully but when I open the console in my browser I see this error:</p>
  <pre><code>ERROR TypeError: Cannot read properties of undefined (reading 'substr')           core.js:14597 
  at TruncatePipe.push../src/app/_services/truncate.ts.TruncatePipe.transform (truncate.ts:11:21)
  </code></pre>
  <p>If I understand this properly there is something wrong with the bellow code in my truncate.ts file. Here is my code:</p>
  <pre><code>import { Pipe, PipeTransform } from '@angular/core';
  
  @Pipe({
    name: 'truncate'
  })
  export class TruncatePipe implements PipeTransform {
    transform(value: string, limit = 25, completeWords = false, ellipsis = '...') {
      if (completeWords) {
        limit = value.substr(0, limit).lastIndexOf(' ');
      }
      return `${value.substr(0, limit)}${ellipsis}`;
    }
  }
  </code></pre>
  <p>I am not sure what is wrong here? Any thoughts what could be wrong?</p>