Javascript 如何在angularjs中将多个参数传递给$interval

Javascript 如何在angularjs中将多个参数传递给$interval,javascript,angularjs,Javascript,Angularjs,每次调用$interval时,我都试图更新$scope.iterationCount 我如何才能做到这一点,同时调用vm.life.next$scope.iterationCount应该在每次调用$interval后递增1 function GameController($interval, board, life, $scope){ var vm = this; $scope.time= "1000"; vm.thumbs = []; vm.

每次调用
$interval
时,我都试图更新
$scope.iterationCount

我如何才能做到这一点,同时调用
vm.life.next
<代码>$scope.iterationCount应该在每次调用
$interval
后递增1


function GameController($interval, board, life, $scope){
      var vm = this;

      $scope.time= "1000";
      vm.thumbs = [];
      vm.reset = reset;
      vm.load = load;
      vm.togglePlay = togglePlay;
      vm.save = save;
      $scope.iteration=10;
      $scope.userSelect = '\u25CF';
      $scope.w=15;
      $scope.h=15;
      $scope.gridColor = '#ffffff';
      $scope.iterationCount= 0;
      function togglePlay(){
        if(!vm.isStarted && vm.timer){ 
          $interval.cancel(vm.timer);
          vm.isStarted = false;
          return;
        }
        vm.isStarted = true;
        vm.timer = $interval(vm.life.next, $scope.time, $scope.iteration);
      }
根据,第三个参数“count”为

重复的次数。如果未设置,或为0,将无限期重复

因此,它不会递增,而是在到达计数器后停止执行
$interval

您需要做的是:

vm.timer = $interval(function(){
  vm.life.next();
  $scope.iteration++;
}, $scope.time);