我用下面的代码计时器:如何取消订阅/停止Observable?
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();
}
}
}
当我尝试在网上停止定时器:
this.timer.dispose(); // this.timer.unsubscribe();
它不工作对我来说
你想要什么用这个存档? –
我需要停止计时器并以秒为单位修复最后的计时器时间。 – OPV