title: "Trim" directive for angular 2 and reflect changes to ngModel
body: <p>I want to create Angular 2 directive that will tirm spaces only from begining and the end of the text that user has typed into input field.</p>
  
  <p>I have input field</p>
  
  <pre><code>&lt;input trim name="fruit" [(ngModel)]="fruit"/&gt;
  </code></pre>
  
  <p>and directive</p>
  
  <pre><code>import {Directive, ElementRef} from "@angular/core";
  
  @Directive({
    selector: 'input[trim]',
    host: {'(blur)': 'onChange($event)'}
  })
  
  export class TrimWhiteSpace {
  
    constructor(private cdRef:ChangeDetectorRef, private el: ElementRef){}
  
    onChange($event:any) {
      let theEvent = $event || window.event;
      theEvent.target.value = theEvent.target.value.trim();
    }
  }
  </code></pre>
  
  <p>which works fine, removes spaces and changes text in input field, but the problem is that the value in ngModel variable "fruit" is not changed and it still contains text with spaces at the begining or at the end.</p>
  
  <p>I also tried to add following to onChange method</p>
  
  <pre><code>this.el.nativeElement.value = theEvent.trim();
  this.cdRef.detectChanges();
  </code></pre>
  
  <p>and change form (blur) to (ngModelChange), but text in ngModel is not effected.</p>
  
  <p>Any suggestions?</p>