html & angularJS-一个简单的10s倒计时
html:
<!-- Countdown --> <div style="margin: 30px auto; width: 45px; height: 45px; border: 3px solid gray; border-radius: 30px; text-align: center; line-height: 42px; vertical-align: middle; color: blue;"> {{countdown}} </div>
JS:
$scope.countdown = 10; var myTime = setInterval(function() { $scope.$apply(function() { $scope.countdown--; }); }, 1000); // 倒计时10-0秒,但算上0的话就是11s setTimeout(function() { clearInterval(myTime); $scope.countdown.$destroy(); }, 11000);
其实也可以用内置服务$timeout做,可在界面的刷新方面总弄不好,还在探索中...