美文网首页
00005.显示时刻

00005.显示时刻

作者: 笑着字太黑 | 来源:发表于2023-05-25 11:07 被阅读0次

    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' }}
    

    相关文章

      网友评论

          本文标题:00005.显示时刻

          本文链接:https://www.haomeiwen.com/subject/cxlhedtx.html