简体   繁体   English

Angular ui-bootstrap进度条,角度计时器不显示值

[英]Angular ui-bootstrap progressbar with angular-timer not showing value

Please help. 请帮忙。 I am fresh out of sanity. 我出于理智而感到新鲜。

See codepen here for an example . 有关示例,请参见codepen

I have a <timer> from angular-timer that exposes seconds on to the local scope and updates it every second, which is pretty nice. 我有一个来自angular-timer<timer> ,它将seconds暴露给本地范围并每秒更新一次,这非常好。 Something like this: 像这样的东西:

<timer> {{seconds}} </timer>

So, I thought it would also be pretty nice to then use a <progressbar> from angular-ui-bootstrap and have it update the value on each tick. 所以,我认为从angular-ui-bootstrap中使用<progressbar>并让它更新每个tick上的value也是相当不错的。 So, I've gone and done something like this: 所以,我已经完成了这样的事情:

<timer>
  <progressbar value="seconds"></progressbar>
</timer>

This, much to my amazement, does not work. 令我惊讶的是,这不起作用。

So, I went ahead and thought about it for what seems like two full days. 所以,我继续思考它似乎整整两天。 That's probably because it's been two days of banging away at this and I still have no idea what in the world is going on. 那可能是因为已经有两天的时间了,我仍然不知道世界上到底发生了什么。 Anyway, I thought "hey, maybe somehow seconds isn't reeeeeally exposed on the scope, so let's find out if it is, OK? OK." 无论如何,我想:“哎,可能在某种程度上secondsreeeeeally暴露的范围,让我们看看它是,OK?OK。” (maybe talking to myself isn't helping.) (也许和自己说话没有帮助。)

So, I proceeded to type these things: 所以,我继续输入这些东西:

<timer>
  {{seconds}}
  <progressbar value="seconds"></progressbar>
</timer>

and there they are, in all their glory, the seconds. 在他们的荣耀中,他们就是秒。 On my page. 在我的页面上。 Just not in my progressbar. 只是不在我的进度栏中。 Where I want them. 我想要他们的地方。 Of course. 当然。

So, seconds is definitely exposed on the scope. 因此, seconds肯定会暴露在范围内。

Then, I thought "okay. Seconds is on the scope. Maybe progressbar has an isolated scope that isn't inheriting seconds or something. Maybe. But no. I do not believe this is the case. That would make too much sense. 然后,我认为“好吧。秒数就在范围内。也许进度栏有一个孤立的范围,不会继承seconds或者其他东西。也许。但是没有。我不相信这种情况。这太有意义了。

Any help would be like an oasis in a vast desert of frustration. 任何帮助都会像是一片茫茫荒芜的绿洲。

It doesn't work because <timer/> is not isolating the seconds object and therefore not exposing it to outside of its scope, while <progressbar/> isolates the value object. 它不起作用,因为<timer />不隔离秒对象,因此不会将其暴露到其范围之外,而<progressbar />隔离值对象。
To make it work with a common scope you can use the timer-tick event that is fired according to the interval that is defined on the by the timer - and register to this event later Updated codepan 要使它与公共范围一起使用,您可以使用根据计时器定义的间隔触发的timer-tick事件 - 并在以后注册到此事件更新的代码扩展

<div ng-controller="customCtrl">
  <timer interval="1000">
    {{seconds}}
    <progressbar value="timerSeconds"></progressbar>
  </timer>
</div>

app.controller('customCtrl', function($scope) {
 $scope.$on('timer-tick',function(e, val) {
   $scope.timerSeconds = (Math.floor(val.millis / 1000));
 }); 
});

You do not need to use progressbar directive in this case, as there is no javascript in the bootstrap implementation : 在这种情况下,您不需要使用progressbar指令,因为bootstrap实现中没有javascript:

<timer start-time='start' end-time='end'">
   <div class="progress">
      <div class="progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="width:{{ 100 - (100 * millis/(endTime - startTime)) | number:0}}%;">
      </div>
   </div>
 </timer>

Note : the example given in the angular-timer docmentation does not work if you use bootstrap 2. For bootstrap 3, you should use code above 注意:如果使用bootstrap 2,angular-timer docmentation中给出的示例不起作用。对于bootstrap 3,您应该使用上面的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM