可观察类型中不存在属性间隔 [英] Property interval does not exist in the type observable

查看:86
本文介绍了可观察类型中不存在属性间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ngAfterViewInit(){
     Observable.interval(3000).timeInterval().subscribe()=>{};    
}

尝试调用Observable.interval()方法会引发编译器错误 可观察类型中不存在属性间隔."

Trying to invoke the Observable.interval() method it is throwing a compiler error "Property interval does not exist in the type observable".

修改

import { Observable } from 'rxjs/Observable';

请注意,导入语句已包含在内

Note that the import statement is already included

推荐答案

对于RxJS 6 +,Tomasz Kula给出的答案仅在使用rxjs-compat包时适用,仅在转换应用程序的过程中使用从RxJS 5到RxJS 6.

For RxJS 6+ the answer given by Tomasz Kula only applies when using the rxjs-compat package, which should only be used when in the process of converting an application from RxJS 5 to RxJS 6.

在RxJS 6+或更高版本中,使用:

Within RxJS 6+, use:

import { interval } from 'rxjs';

interval(3000).subscribe(x => /* do something */)

请注意,现在应该从'rxjs'导入以前以Observable类型存在的所有Observable创建函数.

Note that any Observable creation function that previously existed on the Observable type, should now be imported from 'rxjs'.

这篇关于可观察类型中不存在属性间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆