Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 754
Thejashwini Dev Avatar asked Mar 30 '18 10:03

Thejashwini Dev


2 Answers

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'.

like image 111
David Walschots Avatar answered Nov 02 '22 16:11

David Walschots


this is correct for angular 6.1.+ and rxjs 6.2.+

import { Observable } from 'rxjs';
import { interval } from 'rxjs';

 interval(1000).subscribe(
         (value: number) => {
           this.secondes = value;
         },
         (error: any) => {
           console.log('error');
         },
         () => {
           console.log('observable completed !');
         }
       );
like image 12
Haykel Maaoui Avatar answered Nov 02 '22 14:11

Haykel Maaoui