$timeout 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>This header will change after two seconds:</p>  
  9.   
  10. <h1>{{myHeader}}</h1>  
  11.   
  12. </div>  
  13.   
  14. <p>The $timeout service runs a function after a sepecified number of milliseconds.</p>  
  15.   
  16. <script>  
  17. var app = angular.module('myApp', []);  
  18. app.controller('myCtrl', function($scope, $timeout) {  
  19.   $scope.myHeader = "wait for a while";  
  20.   $timeout(function () {  
  21.       $scope.myHeader = "Welcome to C#corner";  
  22.   }, 2000);  
  23. });  
  24. </script>  
  25.   
  26. </body>  
  27. </html>