Angular js Array inside another array

2

How do I print an array inside another array, in console.log it looks like this:

 Array[5]
     0:Array[10]
      0:Object
      1:Object
      2:Object
      3:Object
      4:Object
      5:Object
      6:Object
      7:Object
      8:Object
      9:Object
      10:Object
    1:Array[2]
      0:Object
      1:Object

I'm trying to repeat normal and will not, I do not know how I'll be able to do ...

    
asked by anonymous 21.11.2016 / 15:03

3 answers

2

Try to use one ng-repeat inside another:

<div ng-repeat="item in array">
 <div ng-repeat="object in item">
   {{object.name}}
 </div>
</div>
    
21.11.2016 / 15:10
4

You need to ng-repeat within another < ng-repeat >, to access each array and print the values:

Html :

<div ng-app="app">
  <div ng-controller="ctrl">
    <div ng-repeat="array in arrays">
      <div ng-repeat="v in array">      
         {{v.name}}
      </div>
    </div>
  </div>
</div>

Angular :

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

    app.controller('ctrl', ['$scope', function($scope)
    {           
       $scope.arrays = [
        [{'name':'a1'}, {'name':'a2'}],
        [{'name':'a3'}, {'name':'a4'}]
       ];
    }]);

The arrays would be the main and array each internal item.

Example:

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

    app.controller('ctrl', ['$scope', function($scope)
    {          
       $scope.arrays = [
       	[{'name':'a1'}, {'name':'a2'}],
        [{'name':'a3'}, {'name':'a4'}]
       ];
    }]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div ng-app="app">
  <div ng-controller="ctrl">
    <div ng-repeat="array in arrays">
      <div ng-repeat="v in array">      
         {{v.name}}
      </div>
    </div>
  </div>
</div>

References:

21.11.2016 / 15:14
4

Make:

Controller

$scope.meuArray = [];

//meu primeiro array é esse seu array que tem outros arrays dentro

angular.forEach(primeiroArray, function(arrays) {
    $scope.meuArray.push(arrays)
}

HTML

<div ng-repeat="obj in meuArray">
     {{obj.algumAtributo}}
<div>
    
21.11.2016 / 19:24