title: Get the first word of a string in Angular using a Pipe?
body: <p>I'm trying to write a pipe that prints the <code>first word</code> in a string. Following is my erroneous code that undesirably prints the <code>first letter</code> of a string.</p>
  
  <p>For eg.</p>
  
  <p><strong><code>PIPE</code></strong></p>
  
  <pre><code>import { Pipe, PipeTransform } from '@angular/core';
  
  @Pipe({
    name: 'firstWord'
  })
  export class GetFirstWord implements PipeTransform
  {
      transform(value: string, args: any[]): string | boolean
      {
          if (value === null) {return false;}
          const firstWords = [];
          for (let i = 0; i &lt; value.length; i++)
          {
            const words = value[i].split(' ');
            firstWords.push(words[0]);
          }
          return firstWords[0];
      }
  }
  </code></pre>
  
  <p><strong><code>COMPONENT</code></strong></p>
  
  <pre><code>userName: string = 'Chuck Norris';
  </code></pre>
  
  <p><strong><code>TEMPLATE</code></strong></p>
  
  <pre><code>{{ userName | firstWord }}
  </code></pre>
  
  <p><strong><code>OUTPUT</code></strong></p>
  
  <blockquote>
    <p>C</p>
  </blockquote>
  
  <p><strong><code>DESIRED OUTPUT</code></strong></p>
  
  <blockquote>
    <p>Chuck</p>
  </blockquote>