My goal is to dynamically invoke an API at specific intervals. However, when attempting to utilize the following code snippet in Angular 7, I encountered issues with the interval timing. I am seeking a solution for achieving dynamic short polling.
ngOnInit() {
this.liveFunction();
}
liveFunction() {
var list = [{
"id": 1,
"timer": 10000,
"url": "https://www.sampleurl.com/1"
},
{
"id": 2,
"timer": 20000,
"url": "https://www.sampleurl.com/users/1"
}];
for (var i = 0, len = list.length; i < len; i += 1) {
(function (i) {
setInterval(function () {
this.invokeAPI(list[i].url)
}, list[i].timer)
})(i);
}
}
invokeAPI (url) {
//do stuff
}