0

I've implemented the Angular Timer directive (http://siddii.github.io/angular-timer/) in my application which is intended to track time spent across projects. The timer works as it should except for when I stop and restart the timer. Visibly, the timer appears to stop but when I restart it, after waiting 10 seconds for instance, that 10 seconds gets ADDED onto the displayed time and it continues counting from there. So it seems to be constantly running in the background.

I have the following code contained within my controller:

allProjects = [...array of objects here...];

$scope.timerRunning = true;

$scope.startTimer = function (){
    $scope.$broadcast('timer-start');
    $scope.timerRunning = true;
};

$scope.stopTimer = function (){
    $scope.$broadcast('timer-stop');
    $scope.timerRunning = false;
};

$scope.$on('timer-stopped', function (event, data){
    console.log('Timer Stopped - data = ', data);
});

In my view I have the following HTML:

<tr ng-repeat="(key, project) in allProjects">
  <td class="lead">{{project.title}}</td>
  <td>{{project.description}}</td>
  <td>
    <timer autostart="false" interval="1000" start-time="project.time">{{hhours}}:{{mminutes}}:{{sseconds}}</timer>
    <button class="btn btn-xs btn-default start" ng-click="startTimer()">start</button>
    <button class="btn btn-xs btn-default stop"ng-click="stopTimer()">stop</button>
  </td>
</tr>

Angular Timer example I borrowed from: http://siddii.github.io/angular-timer/examples.html#/angularjs-single-timer.

Kutyel
  • 8,575
  • 3
  • 30
  • 61
Kirk P.
  • 23
  • 6
  • check my answer [here](http://stackoverflow.com/a/26882739/1139099) – harishr Feb 16 '15 at 04:27
  • public URL to see example: http://kirkpettinga.com/timevault/#/home – Kirk P. Feb 16 '15 at 04:28
  • Thanks @entre. It seems like your answer is to create a separate directive entirely. I'd like to try making this one work if I can though, unless there's a good reason why it won't. – Kirk P. Feb 17 '15 at 00:31
  • you shouldnt use angular-timer, given it works entierly in jquery like, its not angular way of thing... hence i had written a new directive... – harishr Feb 17 '15 at 06:03
  • This question is answered [here](http://stackoverflow.com/a/35323265/4775223) – Wilmer SH Feb 11 '16 at 20:33

0 Answers0