更新时间:2023-01-16 23:13:12
从Angular本身找到***解决方案真是太好了,它提供了通过JSON及其keyvalue
So great to find the best solution from Angular itself provides pipe to loop through JSON , and its keyvalue
<div *ngFor='let item of jsonObj | keyvalue'>
Key: {{item.key}}
<div *ngFor='let obj of item.value'>
{{ obj.title }}
{{ obj.desc }}
</div>
</div>
WORKIGN DEMO
以前:
组件侧:
objectKeys = Object.keys;
模板端:
<div *ngFor='let key of objectKeys(jsonObj)'>
Key: {{key}}
<div *ngFor='let obj of jsonObj[key]'>
{{ obj.title }}
{{ obj.desc }}
</div>
</div>
WORKING DEMO