top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is difference between $timeout and window.setTimeout in AngularJS?

0 votes
268 views
What is difference between $timeout and window.setTimeout in AngularJS?
posted Nov 18, 2017 by Jayshree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

$timeout is an Angular service which wraps the browser's window.setTimeout() function into a try/catch
block and delegates any exceptions to $exceptionHandler service. It is used to call a JavaScript function after a
given time delay. The $timeout service only schedules a single call to the function.

var app = angular.module("app", []);
app.controller("MyController", function ($scope, $timeout) {
 $timeout(callAtTimeout, 1000);
});
function callAtTimeout() {
 console.log("Timeout occurred");
}
answer Nov 18, 2017 by Shivaranjini
...