Why am I getting a 'syntax error: unexpected identifier' and why does my browser gets stuck in a continuous loop after I run this code? I'm using setInterval to delay the requests to the API per the API request guidelines.
var tempArray = [];
var arr = [];
//angular controller
for (var i = 0; i < 10; i++) {
setInterval($http.get(url).success(function(data) {
tempArray.push(data);
arr.push(tempArray);
}), 1000);
}
setTimeout- usingsetIntervalwill continually call the supplied function every 1 second.$timeoutservice for delays because it properly integrateswindow.setTimeoutwith the AngularJS framework. For more information, see AngularJS $timeout Service API Reference;$timeoutandwindow.setTimeoutrequire the first argument be a function. The $http service returns a promise object.