实例如下:
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组件中定时刷新并清除定时器的实例讲解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持靠谱客。
最后
以上就是活泼手链最近收集整理的关于angular2组件中定时刷新并清除定时器的实例讲解的全部内容,更多相关angular2组件中定时刷新并清除定时器内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复