Keyvalue pipe using to print nested values

坚强是说给别人听的谎言 提交于 2019-12-10 12:18:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!