Iterate over object in Angular

前端 未结 17 1339
攒了一身酷
攒了一身酷 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:42

    So I was going to implement my own helper function, objLength(obj), which returns just Object(obj).keys.length. But then when I was adding it to my template *ngIf function, my IDE suggested objectKeys(). I tried it, and it worked. Following it to its declaration, it appears to be offered by lib.es5.d.ts, so there you go!

    Here's how I implemented it (I have a custom object that uses server-side generated keys as an index for files I've uploaded):

            
    

提交回复
热议问题