-1

Can any one please tell me how the setInterval() in angular is working .is java script functionality they implement in angular js ?

gvsk225
  • 31
  • 1
  • 6
  • 1
    Whhhataya mean? – stwilz Aug 02 '18 at 03:56
  • 1
    This would have been a good opportunity to search "setInterval JavaScript" first and learn what it is. – stealththeninja Aug 02 '18 at 04:16
  • @gvsk255 I think the issue you may be having is that the way you have your typescript configured is such that it doesn't recognise `setInterval` as a function. You may need to update you linting. – stwilz Aug 02 '18 at 04:56

2 Answers2

0

setInterval is a function that is exposed by the browser window as part of the global scope. Angularjs just makes use of it like any other javascript code could.

https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval

Paul
  • 35,689
  • 11
  • 93
  • 122
0
setInterval is a function that continually invokes a callback after every X milliseconds, where X is provided to setInterval.

// setInterval usage
function callback(){
  console.log("callback is called continuously");
}

var repeat = 3000;
setInterval(callback, repeat);

It will continue to run as long as your program is running.


Here's another example but with canceling setInterval
var num = 0;
var intervalId = setInterval(function() {
  num++;
  console.log("num:", num);
  if(num === 3){
    clearInterval(intervlId);
  }
}, 1000);

// output
num: 1
num: 2
num: 3