Use Angular ng-repeat to iterate over a layered array

I try my best to make the array look as I would like.

I have:

$scope.array = [["one", "two", "three", "four"], "five"],["six", "seven", "three", "four"], "two"]];

And I want to iterate and display the rows in the first array. I would like to display:

one two three four six seven three four

I currently have the following:

<p ng-repeat="a in array">{{a[0]}}</p>

But it goes like:

["one", "two", "three", "four"]

["six", "seven", "three", "four"]

I tried a filter to remove quotes, etc., but it continues to pull up another array.

+4
source share
1 answer

try it

<div ng-repeat="item in array">
  <div ng-repeat="a in item[0]">
    {{a}}
    </div>
</div>

and the array should look like this

 $scope.array =
 [
   [["one", "two", "three", "four"], "five"],
   [["six", "seven", "three", "four"], "two"]
 ];

var app = angular.module('app', []);
app.controller('main', ['$scope', function($scope) {
  $scope.array = [
    [
      ["one", "two", "three", "four"], "five"
    ],
    [
      ["six", "seven", "three", "four"], "two"
    ]
  ];
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller=main>
  <div ng-repeat="item in array">
    <div ng-repeat="a in item[0]">
      {{a}}
    </div>
  </div>
</div>
Run codeHide result
+6
source

Source: https://habr.com/ru/post/1678845/


All Articles