Joe82 Joe82 - 5 months ago 89
AngularJS Question

Angular JS - ng-repeat first element from an array of arrays

I have a set of data like this

$scope.data = [
["Orange", 3],
["Blue", 2],
["Pink", 1],
["Red", 1],
["Black", 2],
];


I would like to do an ng-repeat that outupts just the first element of each array inside the main array (in other words, just the colors, but not the numbers). So far I made this code

<div ng-controller="myCtrl">
<div ng-repeat="color in data">
<div ng-repeat="n in color">
{{n}}
</div>
</div>
</div>


You can find a jsFiddle here

I tried to use
ng-repeat"n[0] in color"
, but the output is not the desired. Any idea would be appreciated. Thanks!

Answer

Try this:

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