How to clear or stop timeInterval in angularjs?

后端 未结 5 1915
不知归路
不知归路 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:52

    When you want to create interval store promise to variable:

    var p = $interval(function() { ... },1000);
    

    And when you want to stop / clear the interval simply use:

    $interval.cancel(p);
    

提交回复
热议问题