Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 rxjs missing observable.interval method

I'm trying to use the interval method of an observable but I keep getting the error

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

I added these imports:

import "rxjs/Rx"; import "rxjs/add/observable/interval"; import "rxjs/observable/IntervalObservable"; 
like image 692
David Limkys Avatar asked May 06 '16 14:05

David Limkys


2 Answers

You need to import the Observable class this way to be able to use the interval method:

import {Observable} from 'rxjs/Rx'; 

or

import {Observable} from 'rxjs/Observable'; import 'rxjs/add/observable/interval'; 
like image 78
Thierry Templier Avatar answered Oct 04 '22 02:10

Thierry Templier


If you want to create an interval (Observable) with rxjs v6.2.1:

import { interval } from 'rxjs'; // instead of: // import { Observable } from 'rxjs/Observable'; // import 'rxjs/add/observable/interval';  const counter = interval(1000);   // instead of: // const counter = Observable.interval(1000); 
like image 41
Jean-Sébastien Kervella Avatar answered Oct 04 '22 03:10

Jean-Sébastien Kervella