angular5 清除定时器

ngOnDestroy

在指令被销毁前,将会调用 ngOnDestory 方法。它主要用于执行一些清理操作,比如:移除事件监听、清除定时器、退订 Observable 等。

 

调用方法

1.

import { Component , OnInit, OnDestroy} from '@angular/core';

2.
export class ExamDetailComponent implements OnInit, OnDestroy {}

3.

    ngOnDestroy() {
        clearInterval(this.allTimeCount);
    }

 

posted @ 2018-02-26 11:03  boyanh  阅读(2400)  评论(1编辑  收藏  举报