我正在尝试从超时功能更新范围变量和计数器值,但某种方式视图没有更新。这是我的代码:
var countDown = 30, timer;
if (status.statusCode="401") {
$scope.showCounter = true;
$scope.disabledLoginBtn = true;
$scope.error = 'login.user.block.text';
$log.info("countDownStart: ");
_countDowner();
}
function _countDowner() {
if (countDown <= 0) {
countDown = 0;
$scope.disabledLoginBtn = false;
$scope.showCounter = false;
$scope.error = null;
$timeout.cancel(timer);
$log.info("counter: finish ");
return;
} else {
countDown--;
$scope.countDown_text = countDown + " Second";
$log.info($scope.countDown_text);
timer = $timeout(_countDowner, 1000);
}
}
当status.statusCode="401"
条件满足此计数器启动时,我可以看到倒计时在控制台中打印一个值但不知何故所有范围变量如$scope.showCounter, $scope.disabledLoginBtn $scope.error
都没有在视图上更新。我有点困惑为什么会发生这种情况。有人可以告诉我一个原因。