Angular 2 setinterval() keep running on other component

前端 未结 3 1001
醉酒成梦
醉酒成梦 2020-12-23 16:11

I have the following method in one component:

ngOnInit()
        {
            this.battleInit();
            setInterval(() => {
                this.bat         


        
3条回答
  •  醉梦人生
    2020-12-23 16:55

    every 40 seconds

     polling: any;
    
      ngOnInit() {
    
        this.consulta();
        this.pollData();
      }
    
     pollData () {
        this.polling = setInterval(() => {
        this.consulta();
    
      },40*1000)
    
     ngOnDestroy() {
        clearInterval(this.polling);
      }
    

提交回复
热议问题