角度计时器 - 计时器不停止

时间:2015-02-16 04:23:05

标签: javascript angularjs timer angular-timer

我在我的应用程序中实现了Angular Timer指令(http://siddii.github.io/angular-timer/),用于跟踪项目间的时间。计时器正常工作,除非我停止并重新启动计时器。可见,计时器似乎停止但是当我重新启动它时,例如等待10秒后,10秒会在显示的时间内加上ADDED并继续从那里开始计数。所以它似乎一直在后台运行。

我的控制器中包含以下代码:

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

在我的视图中,我有以下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示例我借鉴了:http://siddii.github.io/angular-timer/examples.html#/angularjs-single-timer

0 个答案:

没有答案