title: OrderBy pipe in angular 4
body: <p>I'm trying to write sorting pipe according to code in this link:
  <a href="http://www.advancesharp.com/blog/1211/angular-2-search-and-sort-with-ngfor-repeater-with-example" rel="nofollow noreferrer">http://www.advancesharp.com/blog/1211/angular-2-search-and-sort-with-ngfor-repeater-with-example</a>
  Although I have trouble with dealing with undefined values. My pipe works correctly on columns where there are not any undefined values. But when there is at least one undefined value in column pipe work in a strange way.
  My code below:</p>
  
  <p>html template:</p>
  
  <pre><code>*ngFor="let candidate of filteredList | orderBy:{property: column, direction: direction}"
  </code></pre>
  
  <p>in html template to choose column and direction eg:</p>
  
  <pre><code>&lt;th class="pointer" nowrap="nowrap" (click)="sort('lastName')"&gt;{{ 'candidates.candidates' | translate }}
        &lt;i class="fa" [ngClass]="{'fa-sort': column != 'lastName',
                          'fa-sort-asc': (column == 'lastName' &amp;&amp; !isDesc),
                          'fa-sort-desc': (column == 'lastName' &amp;&amp; isDesc) }"
           aria-hidden="true"&gt; &lt;/i&gt;&lt;/th&gt;
  </code></pre>
  
  <p>order-by.pipe.ts</p>
  
  <pre><code>import { Pipe, PipeTransform } from '@angular/core';
  
  @Pipe({
    name: 'orderBy'
  })
  export class OrderByPipe implements PipeTransform {
  
    transform(candidates: Array&lt;object&gt;, args?: any): any {
      candidates = candidates || [];
      return candidates.sort(function (a, b) {
  
        if (a[args.property] === b[args.property]) {
          return 0;
        }
        if (a[args.property] === '' || a[args.property] === null || typeof a[args.property] === 'undefined') {
          return 1;
        }
        if (b[args.property] === '' || b[args.property] === null || typeof b[args.property] === 'undefined') {
          return -1;
        }
        if (a[args.property] &lt; b[args.property]) {
          console.log(a[args.property] + ' wartosc property');
          return -1 * args.direction;
        } else if (a[args.property].toLowerCase() &gt; b[args.property].toLowerCase()) {
          return 1 * args.direction;
        } else {
          return 0;
        }
      });
    }
  }
  </code></pre>
  
  <p>component.ts:</p>
  
  <pre><code>public sort(property: string) {
      this.isDesc = !this.isDesc;
      this.column = property;
      this.direction = this.isDesc ? 1 : -1;
    }
  </code></pre>
  
  <p>I was trying many different approaches but none of then was worinkg fine.</p>