Using timeouts in Angular JS

Angular provides $timeout, a wrapper forwindow.setTimeout. To use $timeout you will need to inject it into your controller.


$timeout(fn[, delay][, invokeApply]);


var app = angular.module('myApp', []);

function Ctrl($scope, $timeout) {  
     $scope.message = "Hello";
     $timeout(function(){$scope.message = "Hello after 3 seconds";}, 3000);       

Update : Found this really interesting thread on SO – What advantage is there in using the $timeout in Angular JS instead of window.setTimeout?

Hope this helps :)