[英]how to iterate *ngFor through Different objects in array in Angular?
我從 API(服務器)動態生成了不一致的對象數組。
例如:
array = [
{name: 'blah', age:2},
{status: 'pending', date: '20-20-2020'},
{blah: 'foo', google: 'bar'},
{apple: 'android', microsoft: 'eeewww'}
]
這個數組可以是任何具有不同鍵和值的東西。
我如何遍歷它以顯示
ngFor
中的值?
我目前正在做的事情:
this.printArray = JSON.stringify(JSON.parse(this.array), null, 4);
<div *ngFor="let print of printArray">
{{print}} // it prints the array like {"name": blah, "age": 2} but i don't want it in this way
</div>
您可以使用Angular 鍵值 pipe
<div *ngFor="let element of myArray">
<!--element is an object-->
<div *ngFor="let item of element|keyvalue">
{{item.key}}:{{item.value}}
</div>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.