https://qiita.com/karintou/items/04a279a92f2055ee07a1
TS:
import { Observable} from 'rxjs';
private now: Observable<Date>;
private intervalList: any[] = [];
constructor() { // ngOnInit()
this.now = new Observable((observer) => {
this.intervalList.push(
setInterval(() => {
observer.next(new Date());
}, 1000)
);
});
}
ngOnDestroy() {
if (this.intervalList) {
this.intervalList.forEach((interval) => {
clearInterval(interval);
});
}
}
HTML:
{{ now | async | date:'HH:mm:ss' }}
网友评论