问题
Here my stackblitz https://stackblitz.com/edit/angular-vj4llg
To print nested array values, I am using Keyvalue pipe
<p>Use keyvalue pipe</p>
<ul *ngFor="let stdObj of student">
<li>ID : {{stdObj.id}} Name : {{stdObj.name}}
<ng-container *ngFor="let test of stdObj?.value | keyvalue">
{{test.key}} : {{test.value}}
</ng-container>
</li>
</ul>
In typescript
this.student = [
{
id:123,
name: "Test",
value:["{pass: true,verified: true}"]
},
{
id:435,
name:"Test12",
value:["{pass: false, verified: true}"]
}
]
Expecting ouput as
ID : 123 Name : Test pass : true verified : true
回答1:
Currently by your definition, value key holds an array of string: ["{...}"], so the output for it will not show what you expected; instead, it will output index value 0 as 'key' value for the first item, while "{...}' as its value.
So in order to get what you expected, re-defined value as below:
value: {pass: true,verified: true}
来源:https://stackoverflow.com/questions/55723951/keyvalue-pipe-using-to-print-nested-values