【发布时间】:2014-03-24 17:33:27
【问题描述】:
我有一个倒计时指令,一旦模式警告用户他们的会话即将超时,它就会从元素中的初始值倒计时到 0。一旦倒计时达到零,系统会提示用户退出或继续。如果他们点击继续,最终如果他们得到相同的会话到期警告模式,则计数器为 0。我无法完全弄清楚如何重置计数器指令,而不只是返回它并在所有未来的警告中停止它。这是我现在拥有的代码。
.directive("ndCountdown", function($timeout, $compile){
return{
restrict: 'A',
link: function(scope, element, attrs){
var countdown = function(){
var timer = element.find('strong');
for(var i = 0; i < timer.length; i++){
var secs = parseInt(timer.text(), 10) - 1;
if(secs >= 0){
timer.text(secs);
} else{
//reset the element to the original value
//stop the timeout in this session but have it continue to
//work in future dialogs.
}
}
$timeout(countdown, 1000);
}
countdown();
}
}
});
【问题讨论】:
标签: javascript angularjs timeout