Tried to make a simple timer and need to break it on some if
condition. But always got an error EXCEPTION: timer.unsubscribe is not a function
.
What am I doing wrong?
let timer:any = Observable.timer(0,1000);
timer.subscribe(data => {
console.log(this.itemsRatedList);
if(data == 5) timer.unsubscribe();
});
It should be:
You can't
unsubscribe
anObservable
, only aSubscription
.Plunker example
A more clear and simple example is this try this example, I think is more clear.