【问题标题】:Window doesn't update during $interval$interval 期间窗口不更新
【发布时间】:2019-04-21 12:38:21
【问题描述】:

我正在尝试在$interval 中传递一个函数,但不是每个参数都在控制台中更新。

Plnkr 链接:https://plnkr.co/edit/rXAtMCXcZIV2HdlSiZVX?p=preview

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

上述语句更新$scope.iterationCount,但不更新vm.life.next。后者保持初始状态。

当我这样做时:

vm.timer = $interval(vm.life.next, $scope.time, $scope.iteration);

vm.life.next 更新了,但是我没办法更新$scope.iterationCount

【问题讨论】:

  • 我在您的代码中没有看到任何控制台...
  • 对不起。控制台是指窗口。

标签: javascript angularjs


【解决方案1】:

如果vm.life.next是更新生命的函数,那么这里

vm.timer = $interval(vm.life.next, $scope.time, $scope.iteration);

它被调用(在一个区间内),但是在这里

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

它没有 - () 丢失了。应该是vm.life.next();

【讨论】:

  • 非常感谢!!我不敢相信我在一些缺少的括号上浪费了 3 个小时。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-05
  • 2013-09-09
相关资源
最近更新 更多