1

I have JSON object:

content = 
[
{
   "id":1,
   "name":"test",
   "parent":{
      "name":"test2",
      "subParent":{
         "name":"test3",
         "subParent":{
            "name":"test4",
            "subParent":{
               "name":"test5",
               "subParent":null
            }
         }
      }
   }
}
]

How to iterate through each nested object and display the data in Angular?

I tried to do it with ngFor but it doesn't work

1
  • Could you show your .html please ? Commented Dec 20, 2022 at 15:31

1 Answer 1

1
<ul>
  <li *ngFor="let data of content">
    {{data.id}}
    <ul>
      <li *ngFor="let p of data.parent">
        {{p.name}}
      </li>
    </ul>
  </li>
</ul>

You can try something like that, but recursive templates is for me, the right way to do that.

Regards,

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.