2016-07-27 48 views
0

我有一段時間在我的UI中,在這段時間內使用AngularJS Interval不斷更新。即使毫秒也不斷運行。牢記這一點,有可能暫停時間當我徘徊在它。幫助真的很感激。以下是代碼。如何在AngularJs間隔中懸停和暫停時間?

UI的圖像

enter image description here

HTML

<div class="container"> 
<div class="row "> 
<div class="col-lg-12 text-center" ng-app="myApp" ng-controller="myCtrl"> 
<h3 ><b id="thetime">{{theTime| date:'hh:mm:ss sss a'}}</b></h3> 
</div> 
</div> 
</div> 

AngularJS代碼

var app = angular.module('myApp', []); 
app.controller('myCtrl', function($scope, $interval) { 
    $scope.theTime = new Date(); 

    $interval(function() { 
     $scope.theTime = new Date();  
    }, 6); 

}); 

回答

1

ng-mouseover停止ng-mouseleave間隔功能啓動間隔功能

$scope.startInterval = function(){ 
     $scope.flag = $interval(function(){ 
         $scope.theTime = new Date(); 
        }, 6); 
    } 

    $scope.stopInterval= function(){ 
     if($scope.flag) 
     $interval.cancel($scope.flag); 
    } 
    $scope.startInterval(); 

https://jsfiddle.net/ebinmanuval/7qo4jtjv/

+0

由於FR響應..但是,這並不工作..the時間本身停止移動。它仍然停止。 – Jeeva

+0

回答更新,結帳小提琴 –

+0

哇!現在這真棒。非常感謝好友。 – Jeeva