[英]Can I display $timeout value in progress bar?
I'm thinking about displaying the value of my $timeout
to show the people when their time is up.我正在考虑显示我的
$timeout
的值,以在他们的时间到时向人们展示。 The problem is I can't find anything on the internet about it.问题是我在互联网上找不到任何关于它的信息。
So my question is...所以我的问题是...
Is it possible to show the value of your $timeout
in a progress bar ?是否可以在进度条中显示
$timeout
的值?
(I know that this is probably not a valid SO question, but I just want to know the answer.) (我知道这可能不是一个有效的 SO 问题,但我只想知道答案。)
If what you want is after starting a $timeout, find out how long it has left - then the answer is no .如果您想要的是在开始 $timeout 之后,找出它还剩下多长时间 - 那么答案是否定的。
It is however a small difficulty, easily bypassed.然而,这是一个小困难,很容易绕过。
You can create a service
that implements all functionality from $timeout
and provides an extra function that returns you the time left,您可以创建一个实现
$timeout
所有功能的service
,并提供一个额外的函数来返回剩余时间,
Or the easier option that when providing the delay for your $timeout, save the time when you executed the $timeout and at any time you can compare it with new Date()
and see how much time is left.或者更简单的选择是,在为 $timeout 提供延迟时,保存执行 $timeout 的时间,并随时可以将其与
new Date()
进行比较,看看还剩多少时间。
You can probably use a custom directive which can accept a number of timeout and the same number you can pass to your $timeout
function.您可能可以使用自定义指令,该指令可以接受多个超时时间以及可以传递给
$timeout
函数的相同数量。
In this way you can achieve what you want.通过这种方式,您可以实现您想要的。
An available library: http://siddii.github.io/angular-timer/一个可用的库: http : //siddii.github.io/angular-timer/
I think you are probably searching for something like this:-我想你可能正在寻找这样的东西:-
$scope.count = 10000;
var now = new Date();
now = now.getTime();
var date_new;
function show (){
$timeout(function() {
date_new = new Date();
date_new = date_new.getTime();
}, $scope.count);
}
$scope.showTime = function () {
show();
if( date_new ) {
var disable = $timeout(function() {
now = new Date();
now = now.getTime();
$scope.showTiming = now - date_new;
if ($scope.showTiming >= $scope.count)
disable();
}, 10, false);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.