title: How to sort a list of objects using an Angular 2 Pipe
body: <p>I am trying to create a pipe that will sort an array of a custom type.</p>
  
  <pre><code>// custom-object.ts
  export class CustomObject {
      constructor(
          public someString: string,
          public someNumber: number
      ) {}
  }
  </code></pre>
  
  <p>In my html is:</p>
  
  <pre><code>// custom-object-form.component.ts
  &lt;div class="form-group"&gt;
      &lt;label for="cricos_course_code"&gt;Object: &lt;/label&gt;
      &lt;select class="form-control" required [(ngModel)]="model.someString"&gt;
          &lt;option *ngFor="#object of (customObjects | sortArrayOfCustomObjects)" [value]="object.someString"&gt;{{object.someString}}&lt;/option&gt;
      &lt;/select&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Then the code for the pipe:</p>
  
  <pre><code>// sort-custom-object.pipe.ts
  import {Pipe, PipeTransform} from 'angular2/core';
  import {CustomObject} from '../custom-object';
  
  @Pipe({name: 'sortArrayOfCustomObjects'})
  export class SortArrayOfCustomObjectsPipe implements PipeTransform {
    transform(arr:Array&lt;CustomObject&gt;): any {
      return arr.sort((a, b) =&gt; {
        if (a.someString &gt; b.someString) {
          return 1;
        }
        if (a.someString &lt; b.someString) {
          return -1;
        }
        // a must be equal to b
        return 0;
      });
    }
  }
  </code></pre>
  
  <p>Now I am getting an error in the console:</p>
  
  <pre><code>EXCEPTION: TypeError: Cannot read property 'sort' of undefined in [(customObjects | sortArrayOfCustomObjects) in FormComponent@7:24]
  </code></pre>