Scenario:
Displaying the expansion panel name and content Dynamically using Angular material expansion panel using JSON.
Issue:
I able to place the Panel name Dynamically but for the content, I need to check the JSON in that I have a type key so based on type I need to push that particular functionality that particular div.
JSON:
[{
module: "Person Details",
type: 'table',
moduleData: [
{
"firstName":"MaxRunner",
"ID":"12345",
}
]
},
{
module: "Current Location",
type: 'horizontal-stepper',
CurrentData: [
{
"step":1,
"description":"Philips",
"status":true
},
{
"step":2,
"description":"Philips",
"status":true
},
{
"step":3,
"description":"Philips",
"status":false
}
]
}
];
here based on type key and I am pushing the moduledata key to the div present what I did was like I manually gave the key names but suppose in future in future if I have objects then I manually cannot set each name in div so is there any dynamically way to do this?
what I did
<div *ngIf="module.type==='table'">
<div *ngFor="let moduleKey of getKeys(module.moduleData[0])">
<div > {{ moduleKey }} </div>
<div> {{module.moduleData[0][moduleKey]}} </div>
</div>
</div>
<div style="border-bottom:0;" *ngIf="module.type==='horizontal-stepper'">
<div [ngClass]="'col-xs-3' + getStatusClass(step, index, module.CurrentData)" *ngFor="let step of module.CurrentData; let index = index">
<div><div class="progress-bar"></div></div>
<div >{{step.step}}</div>
<div class="bs-wizard-info text-center" *ngIf="isActive(step.status, index, module.CurrentData)">{{step.description}}</div>
</div>
</div>
IN the code currently, I am implementing a manual way like giving the key name "module.CurrentData"
here I don't want to give name manually like "getStatusClass(step, index, module.CurrentData)"
Here is my stackblitz.