How to do ng-repeat query with multiple arrays?

0

I have a blog and I need to get the url of the images of each post. Only they are inside the arrays and I am not getting.

The image illustrates the path. Can someone help me?

The red dots show. I have 3 posts and in post1 I have 9 images attached.

Thanks for everyone's help.

    
asked by anonymous 31.12.2016 / 02:10

1 answer

0

First you should create a ng-repeat to get the posts, inside this ng-repeat you must create another to get the attachments with the urls, follow the example below:

var myApp = angular.module('myApp', []);

myApp.controller('MyController', function($scope){
  
  
  $scope.meuObjeto = {count: 3, pages: 1, posts:
                      [{ attachments: 
                          [
                            {
                              id: 1,
                              caption: 'Teste caption',
                              description: 'Teste description',
                              url: 'http://www.stackoverflow.com/'
                            },
                            {
                              id: 2,
                              caption: 'Teste caption 1',
                              description: 'Teste description1',
                              url: 'http://pt.stackoverflow.com/'
                            }
                          ],
                        outroAtributo : 'Teste outro atributo'
                        
                      },
                      { attachments: 
                          [
                            {
                              id: 3,
                              caption: 'Teste caption2',
                              description: 'Teste description2',
                              url: 'http://www.google.com/'
                            }
                          ],
                        outroAtributo : 'Teste outro atributo'
                        
                      },
                      ]
                     };
              
  
  
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script><divng-app="myApp" ng-controller="MyController">
  <ul>
    <li ng-repeat="post in meuObjeto.posts track by $index">
      {{$index}}
      <ul>
        <li ng-repeat="att in post.attachments track by att.id">{{att.url}}</li>
      </ul>
    </li>
  <ul>
</div>
    
31.12.2016 / 04:58