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
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'
.
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 !');
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With