0

I'm trying to show the values of a specific JSON in the right Order. My JSON looks like :

{
"A":[{"id":"21","name":"Andrea"},{"id":"22","name":"Apple"}],
"B":[{"id":"21","name":"Baby"},{"id":"22","name":"Bali"}],
"C":[{"id":"21","name":"Candle"},{"id":"22","name":"Canada"}],
}

How to show values with ng-repeat :

<div ng-repeat="item in items">

</div>

like :

A

Andrea

Apple

B

Baby

Bali

C

Candle

Canada

2

4 Answers 4

5

Please check working example: http://plnkr.co/edit/lqoQvmXnimWYzqVU0wkg?p=preview

HTML

<div ng-repeat="(key, values) in items">
  {{key}}
  <div ng-repeat="item in values">
    {{item.name}}
  </div>
</div>
Sign up to request clarification or add additional context in comments.

Comments

1

you can iterate over the object with:

<div ng-repeat="(key, value) in jsonData">
   {{key}}
   <div ng-repeat="item in value">
      <div>{{item.name}}</div>
   </div>
</div>

edit: I see the other guys added jsfiddle so enjoy :)

Comments

1

If your data be like this :

$scope.items={
"A":[{"id":"21","name":"Andrea"},{"id":"22","name":"Apple"}],
"B":[{"id":"21","name":"Baby"},{"id":"22","name":"Bali"}],
"C":[{"id":"21","name":"Candle"},{"id":"22","name":"Canada"}],
}

Consider item as map and iterate for (key,value) in map and the value will be associated List. And again iterate for the list in values as -

<div ng-repeat="(key,value) in items">
     {{key}}
     <div ng-repeat="item in value">
       {{item.name}}
     </div>
</div>

Comments

0

Try this plunker.

You print key of your json too so you should use '(key,value)' in ng-repeat to get value of key too.

code:

<div ng-repeat="(key,value) in data">
   {{key}}
    <div ng-repeat="item in value">
      {{item}}
    </div>
</div>

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.