The code is below
import {Component} from 'angular2/core';
import {Observable} from 'rxjs/Rx';
@Component({
selector: 'my-app',
template: 'Ticks (every second) : {{ticks}}'
})
export class AppComponent {
ticks =0;
click(){
let timer = Observable.timer(2000,1000);
timer.subscribe(t=>this.ticks = t);
}
}
But i am getting an error. The error is in the following line:
let timer = Observable.timer(2000,1000);
The definition of error is "property timer doesn't exist on type typeof Observable" Why am I getting error like that? What do you think?
all you need to do is to import Observable from the root folder of library because older versions of rxjs does not provide complete Observable class in rxjs/Observable
If all you need is a timer, you could use this too:
This is the function prototype:
Thats because you havent patched the
timer
method into theObservable
prototype.Update: Rxjs 6.0.0
Import the creation method as a static pure function:
Original answer:
You have 2 options:
1) Patch the method with:
2) Import the operator as a static pure function:
Personally I would recommend the 2nd approach.