0
我有一个倒计时指令,当模态警告用户他们的会话即将超时时,它将从元素中的初始值倒数到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();
}
}
});