Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Angular *ngFor not reading nested data

I am trying to get angular to display some data.

Here is the data:

data = [
   {
      title: 'title1',
      data: [
         {
            id: 1,
            description: 'some description'
         },
         {
            id: 2,
            description: 'some other description'
         }
      ]
   },
   {
      title: 'title2',
      data: [
         {
            id: 1,
            description: 'some description'
         },
         {
            id: 2,
            description: 'some other description'
         }
       ]
    }
 ]

And here is the code I’m trying:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<div *ngFor="let item of data">
   <div>{{ item.title }}</div>
   <ul>
      <li>item.data.description</li>
   </ul>
</div>

The data.description’s are not showing.

How can I get it to display all the data?

>Solution :

data is an array. You need a second *ngFor-block for the data.

  <div *ngFor="let item of data">
    <div>{{ item.title }}</div>
    <ul *ngFor="let itemsdata of item.data">
        <li>itemsdata.description</li>
    </ul>
  </div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading