angular - Latest angular2 form -


i have angular2 version debounce input control, template below.

<input type="text" [ngformcontrol]="compinput" placeholder="demo input" /> 

in component.ts

import {component} "angular2/core"; import {control} "angular2/common"; @component({  ... ) export class demo{   private compinput = new control();   constructor(){     this.compinput.valuechanges.subscribe(() => {});   } } 

these code works until upgrade angular2 version latest. seems form usage has changed.

i changed [ngformcontrol] ngcontrol , control formcontrol "@angular/forms", doesn't work.

does know wrong new usage , how fix?

here's simple example using ngmodel

import {component, input, output, hostlistener, eventemitter, changedetectionstrategy} '@angular/core'; import {observable} 'rxjs/observable'; import {subject} 'rxjs/subject';  @component({   moduleid: module.id,   selector: 'user-search',   changedetection: changedetectionstrategy.onpush,   template: `     <form role="search">       <div class="form-group">         <input           class="form-control"           name="input"           type="text"           placeholder="search user"           [(ngmodel)]="input"           (keyup)="keyup$.next($event.target.value)"         />       </div>     </form>   ` }) export class usersearchcomponent {    input: string;    keyup$ = new subject<string>();    @hostlistener('window:keyup', ['$event'])   cancelsearch(event) {     if (event.code === 'escape') {       this.input = undefined;       this.keyup$.next(undefined);     }   }    @output() search: observable<string> = this.keyup$     .debouncetime(700)     .distinctuntilchanged();  } 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -