import { timer } from 'rxjs';
定义时间变量
timeSubscriber = null;
触发 每隔一秒
startUpdateTime(ms = 1000) {
this.timeSubscriber = timer(0, ms).subscribe(() => {
//操作
});
}
销毁timeSubscriber
stopUpdateTime() {
if (this.timeSubscriber) {
this.timeSubscriber.unsubscribe();
this.timeSubscriber = null;
}
}
网友评论