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);
};