实例如下:
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组件中定时刷新并清除定时器的实例讲解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
解决三元运算符 报错“SyntaxError: can''t assign to conditional expression”
解决angular 使用原生拖拽页面卡顿及表单控件输入延迟问题
使用 Angular RouteReuseStrategy 缓存(路由)组件的实例代码
分享Angular http interceptors 拦截器使用(推荐)
网友评论