How can we run a dynamic loop in angular template with array of object data.
[
{
"name": "name",
"text": "text",
"replies": [{
"name": "Reply1",
"text": "text",
"replies": [
{
"name": "Reply1.1",
"text": "text",
"replies": [{
"name": "Reply1.1",
"text": "text",
"replies": []
}]
}
]
},
{
"name": "Reply2",
"text": "text",
"replies": [
{
"name": "Reply2.1",
"text": "text",
"replies": []
}
]
}
]
}
]
We need to hsow this data in a way we comment on facebook with identation. Replies array can have n number of 'replies' child.
i have wriiten the below code but this is static:
<div *ngFor="let data of jsonData">
<div>
<p>
<b>{{data.name}}</b>
</p>
<p>
<i>{{data.text}}</i>
</p>
<div *ngIf="data.replies.length>= 0">
<div *ngFor="let reply of data.replies" style="margin-left: 8px;">
<p>
<b>{{reply.name}}</b>
</p>
<p>
<i>{{reply.text}}</i>
</p>
<div *ngFor="let subreply of reply.replies" style="margin-left: 8px;">
<p>
<b>{{subreply.name}}</b>
</p>
<p>
<i>{{subreply.text}}</i>
</p>
</div>
</div>
</div>
</div>
<hr>