I have encountered a significant issue in this particular scenario. I am retrieving data from the GitHub API using the code provided below. However, due to GitHub's limitation of only allowing 30 results per page, I would like to fetch all the data for better sorting options and store it in a single array of objects.
$scope.getData = function () {
$http({
method: "GET",
url: apiUrl + pageNum
}).then(function mySuccess(response) {
$scope.myData = response.data;
$scope.isLoading = false;
$scope.result = $scope.myData.map(function (obj) { return { 'name': obj.name, 'html_url': obj.html_url }; });
}, function myError(response) {
$scope.error = response.statusText;
});
};
Although the above code works effectively, I am aiming to achieve something similar to the following:
$scope.getData = function () {
for(var i = 0; i <= $scope.pages.length; i++){
$http({
method: "GET",
url: apiUrl + i
}).then(function mySuccess(response) {
$scope.myData = response.data;
$scope.isLoading = false;
$scope.result = $scope.myData.map(function (obj) { return { 'name': obj.name, 'html_url': obj.html_url }; });
}, function myError(response) {
$scope.error = response.statusText;
});
};
Do you have any suggestions on how to accomplish this task?