angularjs做一个简单的倒计时 [英] angularjs make a simple countdown
本文介绍了angularjs做一个简单的倒计时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想作一个倒计时与角JS。这是我的code:
I would like make a countDown with Angular js. this is my code:
HTML文件
<div ng-app ng-controller = "countController"> {{countDown}} <div>
JS文件
function countController($scope){
$scope.countDown = 10;
var timer = setInterval(function(){$scope.countDown--; console.log($scope.countDown)},1000);
}
在CONSOLE.LOG它的作品我有一个倒计时,但在{{倒计时}}刷新它不
请问你能帮帮我吗?谢谢!
in console.log it works I have a countdown but in {{countdown}} refresh it doesn't could you help me please? thanks!
推荐答案
请看看这里这个例子。这是一个计数了一个简单的例子!我认为,你可以很容易地修改,以创建倒计数。
Please take a look at this example here. It is a simple example of a count up! Which I think you could easily modify to create a count down.
http://jsfiddle.net/ganarajpr/LQGE2/
http://jsfiddle.net/ganarajpr/LQGE2/
function AlbumCtrl($scope,$timeout) {
$scope.counter = 0;
$scope.onTimeout = function(){
$scope.counter++;
mytimeout = $timeout($scope.onTimeout,1000);
}
var mytimeout = $timeout($scope.onTimeout,1000);
$scope.stop = function(){
$timeout.cancel(mytimeout);
}
}
HTML标记:
<!doctype html>
<html ng-app>
<head>
<script src="http://code.angularjs.org/angular-1.0.0rc11.min.js"></script>
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
</head>
<body>
<div ng-controller="AlbumCtrl">
{{counter}}
<button ng-click="stop()">Stop</button>
</div>
</body>
</html>
这篇关于angularjs做一个简单的倒计时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文