2016-08-04 34 views
0

我有一個指導我在哪裏計算定時器倒計時如下提示信息時,定時器0:0

<div stop-watch name="candidateInfo.name" time-of-interview="candidateInfo.dateOfInterview" class="stop-watch"></div> 

    'use strict'; 
angular.module('iSourcingApp.tpModule') 
    .directive('stopWatch', function($state) { 
     return { 
      restrict: 'A', 
      replace: false, 
      scope: { 
       name: "=", 
       timeOfInterview: "=", 
       onSend: '&', 
       startInterview:'&', 
       viewPage:"=" 
      }, 
      controller: function($scope, $interval) {debugger 
       $scope.getTimeRemaining = function(endtime) { 
        $scope.t[$scope.name].total = Date.parse(endtime) - Date.parse(new Date()); 
        $scope.t[$scope.name].seconds = Math.floor(($scope.t[$scope.name].total/1000) % 60); 
        $scope.t[$scope.name].minutes = Math.floor(($scope.t[$scope.name].total/1000/60) % 60); 
        $scope.t[$scope.name].hours = Math.floor(($scope.t[$scope.name].total/(1000 * 60 * 60)) % 24); 
        $scope.t[$scope.name].days = Math.floor($scope.t[$scope.name].total/(1000 * 60 * 60 * 24)); 
       } 
       $scope.initializeClock = function(endtime) {debugger 
        $scope.t = {}; 
        $scope.t[$scope.name] = {}; 
        $scope.updateClock = function() { 
         $scope.getTimeRemaining(endtime); 
         $scope.t[$scope.name].hours = ('0' + $scope.t[$scope.name].hours).slice(-2); 
         $scope.t[$scope.name].minutes = ('0' + $scope.t[$scope.name].minutes).slice(-2); 
         $scope.t[$scope.name].seconds = ('0' + $scope.t[$scope.name].seconds).slice(-2); 

         if ($scope.t[$scope.name].total == 0) { 
          console.log($scope.t[$scope.name].total); 
          $interval.cancel($scope.timeOfInterview); 
         } 
        } 
        $scope.updateClock(); 
        $scope.timeinterval = $interval($scope.updateClock, 1000); 
       } 
       $scope.initializeClock($scope.timeOfInterview); 
      }, 
      templateUrl: function() { 
       var tpl = $state.current.name; 
       return './tpModule/views/' + tpl + '.html'; 
      } 
     }; 
    }); 

但在這裏我無法停止定時器,雖然倒計時達到0

這裏timeOfInterview在ng-repeat中,我使用t[$scope.name]將不同的計時器綁定到不同的候選者。

這裏是結合

<div ng-show="viewPage" class=" btn active interview-timer" ng-click="startInterview();onSend()"> 
<p>Interview Starts in 
    <span class="days" ng-bind="t[name].days"></span>: 
    <span class="hours" ng-bind="t[name].hours"></span>: 
    <span class="minutes" ng-bind="t[name].minutes"></span>: 
    <span class="seconds" ng-bind="t[name].seconds"></span> 
</p> 

任何幫助表示讚賞下面的模板例子。

回答

1

我想你應該叫

$interval.cancel($scope.timeinterval); 

,而不是

$interval.cancel($scope.timeOfInterview); 
+0

謝謝:) 我忽略的變量名 –

相關問題