Dave
Dave

Reputation: 1277

How do you ng-repeat through an object of objects to show key and value?

I have an object called "profile" that includes a handful of other objects -- each one I want to display the label followed by the display_value:

enter image description here

In my HTML, I know I need to ng-repeat through the object profile, but have not been able to get the desired display of label: display_value (i.e. Employment Start Date: 11/20/2019). What is the correct syntax to loop through c.profile and display label followed by display_value? Do I need two ng-repeats in this instance?

<div ng-repeat="item in c.profile track by $index">
  {{item.?}}:  {{item.?}}
</div>

Upvotes: 2

Views: 237

Answers (2)

georgeawg
georgeawg

Reputation: 48948

Use ng-repeat="(key, value) in myObj":

<div ng-repeat="(category, valueObj) in c.profile">
    <h2>{{category}}</h2>
    <div ng-repeat="(key, value) in valueObj">
        {{key}} : {{value}}
    </div>
</div>

For more information, see

Upvotes: 0

Dan
Dan

Reputation: 3815

<div ng-repeat="item in c.profile track by $index">
  {{item.label}}:  {{item.display_value}}
</div>

make sure your data is what you expect it to be.

Upvotes: 1

Related Questions