Ryan
Ryan

Reputation: 6217

AngularJS ng-repeat nested object

My code is outputting this:

How can it output this (without editing the $scope.names object):

Here's my view:

  <body ng-controller="MainCtrl">
        <ul>
            <li ng-repeat="name in names">
                {{name}}
            </li>
        </ul>
  </body>

...and controller:

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

app.controller('MainCtrl', function($scope) {
  $scope.names = {
        "1": {
            "name": "John"
        },
        "2": {
            "name": "Mark"
        }
    };
});

Here's my Plunker: http://plnkr.co/edit/hnjoPH0r9xhlvMzO93Ts?p=preview

Upvotes: 0

Views: 90

Answers (1)

tymeJV
tymeJV

Reputation: 104775

Use {{name.name}} - you're currently just displaying the entire object being iterated over - you need to specify the property as well.

<li ng-repeat="name in names">
    {{name.name}}
</li>

Upvotes: 3

Related Questions