Currently, I am working on a project that involves making an HTTP request using Angular to approximately 1500 URLs in search of JSON data that matches a specific condition (only one URL will match). My current implementation sometimes works, but it seems non-deterministic, possibly due to the asynchronous nature of the requests or maybe there is a bug? As I am new to Angular, I am open to completely changing the code if needed!
this.matchingurl;
this.data;
this.findUrl = function(condition) {
var that = this;
for (var i = 0; i <= ; i++) {
// This loop iterates through the list of URLs
for (var i = 0; i < urlList.length; i++) {
for (var j = 0; j < urlList[i]['list'].length; j++) {
this.url = 'http://' + urlList[i]['list'][j] + restofurl;
var tempUrl = urlList[i]['list'][j];
$http.get(this.url).success(function(data) {
if (condition is met in data) {
that.matchingurl = tempUrl;
return;
}
})
.error(function(data){
// Error handling
});
}
}
}
}
TLDR: The matchingUrl variable does not behave as expected. It enters the "condition" loop but does not output the correct URL. It always returns the same URL for any sublist, whether right or wrong.