Angular2 rxjs missing observable.interval method
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';
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);
It's possible too, for:
"rxjs": "6.3.3"
"rxjs-compat": "^6.5.5"
import { Component, OnInit } from '@angular/core';
import { interval } from 'rxjs';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
constructor() { }
ngOnInit() {
const myNumber = interval(1000);
myNumber.subscribe(
(number: number) => {
console.log(number);
}
);
}
}