时间:2020-10-11 10:45:19 | 栏目:AngularJS | 点击:次
实例如下:
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); } } }