Como cancelar a inscrição / parar o Observable?
Eu uso o seguinte código para timer:
export class TimerService {
private ticks: number = 0;
private seconds: number = 0;
private timer;
constructor(seconds: number) {
this.seconds = seconds;
this.timer = Observable.timer(2000, 1000);
this.timer.subscribe(t => {
this.ticks = t;
this.disactivate();
});
}
private disactivate() {
if (this.ticks === this.seconds) {
this.timer.dispose();
}
}
}
Quando tento parar o cronômetro na linha:
this.timer.dispose(); // this.timer.unsubscribe();
Isto não funciona para mim