问题
I have the following code inside the constructor of my Angular2 component class:
Observable.from([1,2,3]).interval(2000).subscribe(e=>{
console.log(e);
});
I imported the following:
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/from';
import 'rxjs/add/observable/interval';
I have the following error message while building my project using Angulat CLI:
Property 'interval' does not exist on type 'Observable<any>
What am I missing?
回答1:
That's correct. The interval method is a static method that exists only on the Observable class. In other words, it's not an operator.
So you probably want delay or timeout instead.
Observable.from([1,2,3])
.concatMap(val => Observable.of(val).delay(2000))
来源:https://stackoverflow.com/questions/42885687/property-interval-does-not-exist-on-type-observableany