$interval Service in AngularJs

  1. <!DOCTYPE html>  
  2. <html>  
  3. <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>  
  4. <body>  
  5.   
  6. <div ng-app="myApp" ng-controller="myCtrl">  
  7.   
  8. <p>The time is:</p>  
  9.   
  10. <h1>{{theTime}}</h1>  
  11.   
  12. </div>  
  13.   
  14. <p>The $interval service runs a function every specified millisecond.</p>  
  15.   
  16. <script>  
  17. var app = angular.module('myApp', []);  
  18. app.controller('myCtrl', function($scope, $interval) {  
  19.   $scope.theTime = new Date().toLocaleTimeString();  
  20.   $interval(function () {  
  21.       $scope.theTime = new Date().toLocaleTimeString();  
  22.   }, 1000);  
  23. });  
  24. </script>  
  25.   
  26. </body>  
  27. </html>