Search code examples
javascriptjqueryangularjswebangularjs-ng-repeat

Using ng-repeat on a position of $scope


I have a array like:

$scope.items = [];
$scope.items[0] = {val1: 1, val2: 2}

I'm trying to use an ng-repeat like:

<div ng-repeat = "item in items[0]"> {{item.val1}} </div>

which it is the right way to use this? Thanks :D !


Solution

  • items[0] is not an array but object so you need to use (key, value) in expression notation (see docs) to iterate over object properties:

    <div ng-repeat="(key, value) in items[0]">{{key}} {{value}}</div>