I want to call an API every 2 seconds in a loop. How can i achieve this?
var letterArray = ['a', 'b', 'c'];
for (var j = 0; j < letterArray.length; j++) {
$timeout(callApi(letterArray[j]), 2000);
}
function callApi(searchInput) {
var request = {
//
url: 'https://someApi/search?name=' + searchInput,
method: 'GET',
headers: {
'Authorization': 'abc'
}
};
$http(request).then(onComplete, onError);
}