Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

angular - Property interval does not exist in the type observable

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

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

Edit

import { Observable } from 'rxjs/Observable';

Note that the import statement is already included

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

Within RxJS 6+, use:

import { interval } from 'rxjs';

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...