I have this API that has pages 1-10 and I want to loop through the page numbers to make the API calls
app.factory('companies', ['$http', function($http) {
var i;
for (i = 1; i < 11; i++) {
var data = $http.get('https://examplepage.com/wp-json/wp/v2/categories?per_page=50&page=' + i);
console.log('list', data);
}
return data;
}]);
This is what I get when I console log the data for all 10 API calls JSON data
My attempt to display all of the data (list of names), but it seems as though it's only taking the last API call and displaying it. How do I combine all of the returned data into one object to display the list of name from pages 1-10?
app.controller('HomeController', ['$scope', 'companies', function($scope, companies) {
companies.success(function(data) {
$scope.companies = data;
console.log('companies', $scope.companies);
});
}]);
view.html
<div class="container" ng-controller="HomeController">
<div ng-repeat="company in companies" class="list">
<a href="#/{{ company.id }}" class="company-name">{{ company.name }}</a>
</div>
</div>