Siva
Siva

Reputation: 3327

How to display this JSON format using AngularJS

I have two JSON formats,

JSON -

[
    { 
        "name":"Alex", 
        "country":"United States"
    }, 
    { 
        "name":"Jaswanth", 
        "country":"India"
    }
]

AngularJS Code -

I was able to display the output

<div ng-repeat="result in results">             
    {{result.name}} - {{result.country}}
</div>

But if I change my JSON, I am not able to see the output..

[
    {
        "info": [
            "one",
            "two",
            {
                "id": 944589,
                "contractYear": 2014
            }
        ],
        "country": "India",
        "name": "jaswanth"
    },
    {
        "info": [
            "three",
            "four",
            {
                "id": 944589,
                "contractYear": 2014
            }
        ],
        "country": "US",
        "name": "jass"
    }
]

How to I change my AngularJS code ?

Upvotes: 2

Views: 159

Answers (1)

Coldstar
Coldstar

Reputation: 1341

<div ng-init="init();">
    <div ng-repeat="result in data">             
        {{result.name}} - {{result.country}}
        <br/>
        <div ng-repeat="(k,v) in result.info">
            <span ng-if="v.id">The id is: {{v.id}}</span>
            <span ng-if="(!v.id)">{{v}}</span>
        </div>
        <hr/>
    </div>
</div>

Upvotes: 1

Related Questions