Property 'interval' does not exist on type 'Observable<any>'

旧城冷巷雨未停 提交于 2019-12-13 16:15:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!