2016-07-27 45 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