2016-09-17 75 views

回答

5

有做雙向的。

1)不強類型

var keyups = Observable.fromEvent(document, 'keyup') 
    .map((e: any) => e.target.value) // or (<any>e).target.value 
    .debounceTime(200) 
    .filter(text => text && text.length >= 3) 

    keyups.subscribe(data => console.log(data)); 

2)使用強類型

var keyups = Observable.fromEvent(document, 'keyup') 
    .map((e: KeyboardEvent) => (<HTMLInputElement>event.target).value) 
    .debounceTime(200) 
    .filter(text => text && text.length >= 3) 

    keyups.subscribe(data => console.log(data)); 

,我認爲導入完全rxjs庫冗餘,所以它可能是這樣的:

import { Observable } from 'rxjs/Observable'; 
import 'rxjs/add/observable/fromEvent'; 
import 'rxjs/add/operator/map'; 
import 'rxjs/add/operator/debounceTime'; 
import 'rxjs/add/operator/filter'; 

One Note:rxjs /在第一行ö bservable

參見住Plunker