gpt4 book ai didi

javascript - 获取 NaN 而不是数字/值

转载 作者:行者123 更新时间:2023-12-02 14:45:05 25 4
gpt4 key购买 nike

应该是简单的语法错误,但我不知道它是什么

Controller :

    $scope.startCounter=3;

$scope.startTimeouter = function (number) {
$scope.startCounter = number - 1;
mytimeouter = $timeout($scope.startTimeouter, 1000);

if($scope.startCounter<=0){
$timeout.cancel(mytimeouter);
$scope.startTimeout();
}
$scope.startTimerBtner=function(){
$scope.startTimeouter();
}


$scope.stopTimerBtner = function () {
$timeout.cancel(mytimeouter);
}
}

HTML:

<a ng-click="startTimeouter(3);" >Click to Start Timer</a>

结果是“3”..“2”...“NaN”....任何帮助将不胜感激

最佳答案

您没有在 timeout 中将任何内容传递到 $scope.startTimeouter 中,因此 number 的值未定义。相反,将您的函数设置为:

$scope.startCounter=3;

$scope.startTimeouter = function (number) {
$scope.startCounter = number - 1;
mytimeouter = $timeout(function(){$scope.startTimeouter($scope.startCounter)}, 1000);

if($scope.startCounter<=0){
$timeout.cancel(mytimeouter);
$scope.startTimeout();
}
$scope.startTimerBtner=function(){
$scope.startTimeouter();
}


$scope.stopTimerBtner = function () {
$timeout.cancel(mytimeouter);
}

}

关于javascript - 获取 NaN 而不是数字/值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36681675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com