import { timer } from 'rxjs';
定義時間變量
timeSubscriber = null;
觸發(fā) 每隔一秒
startUpdateTime(ms = 1000) {
this.timeSubscriber = timer(0, ms).subscribe(() => {
//操作
});
}
銷毀timeSubscriber
stopUpdateTime() {
if (this.timeSubscriber) {
this.timeSubscriber.unsubscribe();
this.timeSubscriber = null;
}
}