0

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

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

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

4

0 回答 0