Am trying to create a list using mat-list with below Json structure
{
"Parent1": [
{
"Data1": [
"child1",
"child2"
]
}
],
"Parent2": [
{
"Data2": [
"child3",
"child4"
]
}
]
}
Html Code
<mat-list >
<ng-container *ngFor="let item of (jsonData | keyvalue) ;">
<mat-list-item>
<h3 matLine> {{item.key}}</h3>
<mat-icon>close</mat-icon>
<div class="parent-mat-divider">
<mat-divider></mat-divider>
</div>
</mat-list-item>
<ng-container *ngFor="let child of (item |keyvalue) ;">
<mat-list-item *ngFor="let subChild of (child |keyvalue) ;">
{{subChild.value}}
<mat-icon>close</mat-icon>
</mat-list-item>
<mat-list>
On the first page load it showing values like below.I need to avoid those values
I need to create a list like below based on the above Json

Note: Am not sure it is the right way to iterate the object It will appreciate some one give solution.
Thanks in advance.

Solution 1: With
$any()A cheating way by using
$any()type cast function to prevent type checking.Solution 2: Restructure the JSON Data
From my perspective, the data that you want to represent in the HTML is something like:
Hence, you can work with
Object.keys()orObject.entries()(require es2017) to iterate key-value pair and with.reduce()to transform your input data to representation data.Demo Solution 1 & 2 @ StackBlitz