I'm playing with Marvel API as I'm building a character showcase however Marvel limits the amount of results you can retrieve in a single get request to 100.
I've tried to put it inside the for loop but it isn't working. I have tried to implement a method suggested as a solution while
or for
loop with $http.get
My code:
var loopRequests = function(i){
$scope.offsetParam = 0;
$http.get($scope.baseUrl, {
params: {
offset: $scope.offsetParam,
limit: 100,
ts: $scope.timeStamp,
apikey: $scope.publicKey,
hash: $scope.hash
}}).then(function(response){
$scope.characters = response.data.data.results;
});
}
for(var i = 0; i < 2; i++){
loopRequests(i);
$scope.offsetParam += 100;
}
Here's what I'm trying to achieve:
- Request 1: Offset 0, Limit 100
- Request 2: Offset 100, Limit 100
- Request 3: Offset 200, Limit 100
- Request 4: Offset 300, Limit 100 etc...
Any help with this will be appreciated.
//Edit: It needs to wait for the last request to finish