3

Please help. I am fresh out of sanity.

See codepen here for an example.

I have a <timer> from angular-timer that exposes seconds on to the local scope and updates it every second, which is pretty nice. 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. 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." (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.

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.

Any help would be like an oasis in a vast desert of frustration.

3
  • I suspect the progress bar has an isolated scope and you are running into the prototypal inheritance gotcha described here Commented Aug 14, 2014 at 12:49
  • I thought that too, however wouldn't that mean that $parent.seconds would work? Because that doesn't work either. I tried adding a $watch on seconds in a new controller, updating a property and then using that, but that doesn't work either. I've updated the pen to reflect these scenarios. Commented Aug 14, 2014 at 14:01
  • Also, that would mean that setting $scope.value with $interval wouldn't work either. But it does. Commented Aug 14, 2014 at 14:18

2 Answers 2

4

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.
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

<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));
 }); 
});
Sign up to request clarification or add additional context in comments.

Comments

1

You do not need to use progressbar directive in this case, as there is no javascript in the bootstrap implementation :

<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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.