1

In Angular 7, I have nested array of objects as below to iterate. 1st level iteration using *ngFor does work, but nested iteration does not show up any value. Anyone help me what has to be done? Find the below code

Sample JSON

const res = [ {
        2: [ 
            {id:1, cId: 2, name: 'TEST 1'},{id:2, cId: 2, name: 'TEST 2'}
          ],
        8: [ 
            {id: 10, cId: 8, name: 'TEST 10'}
        ]
    }]


<div *ngFor="let country of res[0] | keyvalue;">
   <span> {{country.key}} </span> <!-- Displayed 2 and 8 -->
   <div *ngFor="let airport of country[country.key]">
         <span>{{airport.name}}</span> <!-- name should be displayed, but nothing is coming up-->
   </div>
</div>

1 Answer 1

1

change your html with the following

<div *ngFor="let country of res[0] | keyvalue;">
   <span> {{country.key}} </span> <!-- Displayed 2 and 8 -->
   <div *ngFor="let airport of country.value">
         <span>{{airport.name}}</span> <!-- name should be displayed, but nothing is coming up-->
   </div>
</div>

more specifically you have to replace country[country.key] with country.value

Demo

Sign up to request clarification or add additional context in comments.

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.