Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to iterate JSON object in Angular 2?

Let's say I have a JSON like this:

{
    "A": [
            {"name": "Aa", "count": "21"},
            {"name": "Ab", "count": "54"}
         ],

    "B": [
            {"name": "Ba", "count": "30"},
            {"name": "Bb", "count": "22"}
         ],

    "C": [
            {"name": "Ca", "count": "40"},
            {"name": "Cb", "count": "33"}
         ],
}

Output HTML should like this:

[A]
Aa 21
Ab 54

[B]
Ba 30
Bb 22

[C]
Ca 40
Cb 33

How can I iterate using angular2 Beta version?

like image 225
Zeyar Phyo Maung Avatar asked Oct 19 '22 18:10

Zeyar Phyo Maung


1 Answers

You can use the ng-for directive.

Have a look at this. angular-2-ng-for-syntax

And you should convert your object to an array. Have a look here: a-better-way-to-convert-js-object-to-array

like image 127
harmoniemand Avatar answered Nov 15 '22 06:11

harmoniemand