I have a JSON that has some nested objects in it. So to show them in view, I created this:
<div *ngFor="let item of trees">
<div *ngFor="let obj of item | keyvalue">
<div *ngFor="let obj1 of obj.value | keyvalue">
<div *ngIf="!ifLeaf(obj1.value)">
<b>{{ obj1.key }}</b>
<div *ngFor="let obj2 of obj1.value | keyvalue">
<div *ngIf="ifLeaf(obj2.value)">
<i>{{ obj2.key }}</i>
</div>
</div>
</div>
</div>
</div>
</div>
And the JSON looks like that:
trees[
header: {
first: {
title: {
name: "Test"
}
},
second: {
title: {
top: {
name: "Test"
}
},
desc: {
name: "Test"
}
}
}
]
That code can show up to 2 nested objects with its keys and values. But what if the last object has 3 more nested objects within its own object? Is there a way that I can do that dynamically, without hardcoding? I'm sure there are better solutions for that. I'd be really thankful!
trees