實例如下:
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組件中定時刷新并清除定時器的實例講解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持武林網(wǎng)。
新聞熱點
疑難解答