0

My code is outputting this:

  • {"name":"John"}
  • {"name":"Mark"}

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

  • John
  • Mark

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

1 Answer 1

3

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.