How to clear or stop timeInterval in angularjs?

后端 未结 5 1919
不知归路
不知归路 2020-11-30 19:09

I am making a demo in which I am fetching data from the server after regular intervals of time using $interval Now I need to stop/cancel this.

How I can

5条回答
  •  日久生厌
    2020-11-30 19:49

    var promise = $interval(function(){
        if($location.path() == '/landing'){
            $rootScope.$emit('testData',"test");
            $interval.cancel(promise);
        }
    },2000);
    

提交回复
热议问题