实例如下:

import { Component,OnInit,ChangeDetectionStrategy,ChangeDetectorRef,OnDestroy} from "@angular/core";

@Component({
changeDetection:ChangeDetectionStrategy.OnPush
})

export class xxxComponent{
private timer;
constructor(private ref : ChangeDetectorRef){
this.timer = setInterval(()=>{
this.ref.detechChanges();//检测变化
},5000)
}
//销毁组件时清除定时器
ngOnDestroy(){
if(this.timer){
clearInterval(this.timer);
}
}
}

以上这篇angular2组件中定时刷新并清除定时器的实例讲解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持悠悠之家。

点赞(72)

评论列表共有 0 条评论

立即
投稿
返回
顶部