当调用SetState()时,它应该重置计时器。我只写了取消部分,但它似乎没有取消超时。我也没有从控制台获得任何信息。所以我被卡住了。
$scope.customTimeout = null;
$scope.SlideTimer = function() {
$timeout.cancel($scope.customTimeout);
$scope.customTimeout = $timeout(function() {
if ($scope.slideState == (slideAmount -1))
$scope.slideState = 0;
else
$scope.slideState++;
}, 2000).then(function() {
$scope.SlideTimer();
});
};
$scope.SlideTimer();
$scope.SetState = function(State) {
$scope.slideState = State;
$timeout.cancel($scope.customTimeout);
console.log("set state to " + State);
};
这只是我整个代码的一部分。
提前致谢