简体   繁体   中英

How to write json in Angular getting different values

I know how to print this in Angular from a local jsonFile:

[{
            "Firstname": "Steve",
        "Lastname": "Jansson"
    
        },
        {
            "Firstname": "Kurt",
            "Lastname": "Nilsson"
        },
        {
            "Firstname": "Lisa",
            "Lastname": "Andersson"
        }]

This is is how it looks when im printing it out

   <p> List!</p>
    <ul>
        <li *ngFor="let adress of arrAdressbook; let i = index">{{adress.Firstname}} {{adress.Lastname}} </li>    
    </ul>

But how do I do if I want to print the following?

{
    "Adressbook": [{
            "Firstname": "Steve",
            "Lastname": "Jansson",

            "Adress": [{
                "Street": "Hollowroad 17",
                "City": "Sidney"
            }]
        },
        {
            "Firstname": "Kurt",
            "Lastname": "Nilsson",
            "Adress": [{
                "Street": "Asbroad 14",
                "City": "Canberra"
            }]
        },
        {
            "Firstname": "Lisa",
            "Lastname": "Andersson",
            "Adress": [{
                "Street": "kangahoop 14",
                "City": "Bunberry"
            }]
        }
    ]
}

Any help would be much appreciated! Cheers! //Mcgajver

Much easier than you think. Use angular json pipe https://angular.io/api/common/JsonPipe

<pre>{{ data | json }}</pre>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM