In Angular 2.0.0-beta.0 map() and filter() are mis

2019-04-28 07:48发布

问题:

In Angular 2.0.0-alpha.47 the Observable returned from calling formInput.valueChanges() had all the higher order functions i.e I could do something like this;

this.search.valueChanges
 .debounceTime(150)
 .map(x=>return x+1)
 .switchMap(text => this.youtube.search(text));

I'm now using 2.0.0-beta.0 and the Observable returned from this.search.valueChanges() no longer has all the methods. I can only subscribe. I can no longer call map(), filter() etc.

Does anyone know if this is the expected behaviour for form inputs now?

回答1:

import Rxjs like this :

Import * as Rx from "rxjs/Rx";

The operators will be available.

When you use Observable class .. prefix it with Rx. ( Rx.Observable )



回答2:

Did you try to import this:

import 'rxjs/add/operator/map';

See this issue for more details https://github.com/angular/angular/issues/5632

Hope it helps you, Thierry