vzhen
vzhen

Reputation: 11157

AngularJs ng-repeat within ng-repeat return same data

I need to perform loop within loop in Angularjs to a directive. The first looping is getting links from json file and the second loop is looping the data from previous looped links.

But in the second loop, it returns the same result.

I created a testing plunker. You can see what's wrong here. Thanks

Upvotes: 0

Views: 72

Answers (2)

Maciej Walkowiak
Maciej Walkowiak

Reputation: 12932

When you iterate over jsonLinks you are overwriting $scope.feeds in each iteration. In order to make it work I suggest to replace your loop with: Plunker

angular.forEach($scope.jsonLinks, function(jsonLink) {
    $scope.jsonLink = jsonLink.link;
    dataService.jsonp($scope.jsonLink).then(function(response){
      jsonLink.feeds = response.data.feed;
    });
});

Upvotes: 1

Ketan
Ketan

Reputation: 5891

I had to clear my old answer because it didn't solve the problem. The major issue here is that you are making async calls inside a loop, with no reference to the original jsonLink object where you can store the feeds. You will need a reference to the corresponding parent object for the feed. probably locate it via id and then add the feed to it.

Upvotes: 0

Related Questions