Iterate over object in Angular

前端 未结 17 1551
攒了一身酷
攒了一身酷 2020-11-22 12:19

I am trying to do some things in Angular 2 Alpha 28, and am having an issue with dictionaries and NgFor.

I have an interface in TypeScript looking like this:

17条回答
  •  一生所求
    2020-11-22 12:32

    Updated : Angular is now providing the pipe for lopping through the json Object via keyvalue :

    {{item.key}}:{{item.value}}

    WORKING DEMO , and for more detail Read


    Previously (For Older Version) : Till now the best / shortest answer I found is ( Without any Pipe Filter or Custom function from Component Side )

    Component side :

    objectKeys = Object.keys;
    

    Template side :

    Key: {{key}}
    {{ obj.title }} {{ obj.desc }}

    WORKING DEMO

提交回复
热议问题