how to call function every 2 mins

后端 未结 5 1372
野的像风
野的像风 2021-01-17 16:30

how to call a save function every two mins in anular js. please Help me.

 $scope.save = function () {
        $http({
        url : \'/api/products\',
             


        
相关标签:
5条回答
  • 2021-01-17 16:49

    You could try using the $interval service.

    In case you need something more accurate, consider using an external library.

    0 讨论(0)
  • 2021-01-17 16:54

    You can try the following way also.

    Declaring the interval:

    var interval = null;
    

    To cancel interval:

    if (interval != null)
    
        $interval.cancel(interval);
    

    Call the function as per as interval:

    $interval(function() {
        $scope.function();
    }, 120000);
    
    0 讨论(0)
  • 2021-01-17 17:03

    you can use setInteraval function to call your function every 120000 milliseconds.

    setInterval(function(){
      $scope.save();
    }, 120000)
    
    0 讨论(0)
  • 2021-01-17 17:11

    You can use $interval from angularjs

    setInterval(function(){
      $scope.save();
    }, 120000)
    
    0 讨论(0)
  • 2021-01-17 17:15

    you can use setInteraval function.

     setInterval(function(){
     $scope.save();
     }, 120000)
    
    0 讨论(0)
提交回复
热议问题