应该是简单的语法错误,但我不知道它是什么
控制器:
$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”....任何帮助都将不胜感激
答案 0 :(得分:2)
您未在$scope.startTimeouter
中向timeout
传递任何内容,因此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);
}
}