I have inside a controller several calls $http.get('/...')
that get the data correctly.
$scope.results = [];
$http.get('/call1').then(function(response){
proccess(response);
});
$http.get('/call2').then(function(response){
proccess(response);
});
$http.get('/call2').then(function(response){
proccess(response);
});
The returned data is of the type:
// call 1
{items:{1:{id: 1, title: "Título",…}, 2:{id: 2, title: "Título",…},…}}
// call 2
{items:{1:{id: 10, title: "Título",…}, 2:{id: 20, title: "Título",…},…}}
// call 3
{items:{1:{id: 100, title: "Título",…}, 2:{id: 200, title: "Título",…},…}}
In the function that it processes, since all the structures are the same, it is simple:
function proccess(response){
$scope.results = response.items;
}
Theng-repeat
<div data-ng-repeat="item in results">
{{item.id}}
</div>
And this part is where I find the problem.
In theory I'm trying to ng-repeat
update it with the new data as it gets it.
I have tried with extend
, concat
, merge
, push
... and it always replaces them or throws me errors on the console and I'm a bit stuck with this issue.
How should the answers be joined so that it updates as ng-repeat
it receives the data?
PS.: Any questions, comment and update
The most important problem is that in it you
ng-repeat
useitems
as data source and notresults
(what you set in$scope.results
). As it is, it's going to loop through$scope.items
(which you can't see where you define it).Maybe you didn't use it
concat
correctly. Remember that it does not modify the current array but returns one that has the sum of both arrays so you need to reallocate it.The correct way for it to work is like this: