Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I am new to angular and im creating a simple timer app that creates multiple timers which begin at different times depending on the json object loaded. I have the amount of timers listed properly from my object, I just need help setting the time to start at from the object.

    <li ng-repeat="job in jobs">
     <!--UPDATE COUNTER TO {{job.dur}}-->
     <ul ng-controller = 'counterCtrl' class="button-group">
      <h3 ng-bind="counter"></h3>
       <li> <button ng-click="start()"> Start</li>
     </ul>
    </li>

Essentially I have a counter that counts up using $timeout service. I am importing a json object(as seen below) that has the name of the timer and the current time to start the timer at.

    localjobs = [
          { "name": "job1", 'dur': 10},
          { "name": "job2", 'dur': 20}
    ];

The problem: I want to essentially update the counter with the job.dur value in the json object for each counter that gets loaded. This way each timer will begin at the job.dur time. Would I have to update the ng-repeat directive to run a function like updateCounter(); each time a job is listed? What should I look into more to solve this?

My js timer function called when clicking start:

    $scope.start = function(dur) {
      stopped = $timeout(function() {
        $scope.counter++;   
        $scope.start();
      }, 1000);
  };
share|improve this question
1  
Can't you put your code inside the counterCtrl, since that will be executed for every iteration of the ng-repeat. – Wawy Mar 19 '14 at 15:53
    
I could but then how would I reference the duration number for the current job that ng-repeat is listing? – thesentyclimate413 Mar 19 '14 at 15:57

1 Answer 1

    $scope.counter = $scope.job.dur; 

This set the inital counter value in my js. Thanks to Wawy for the help.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.