Angular 2 - iterating over json array inside a json object

后端 未结 1 1273
情话喂你
情话喂你 2020-12-29 08:20

I\'m learning Angular 2 and I\'ve been working with static arrays, and now I\'m trying to learn more about reading remote data.

My app.component.ts:

相关标签:
1条回答
  • 2020-12-29 08:47

    Plunker

    To loop over Array:

    <li *ngFor="let doc of docs">{{doc.id}}</li>
    

    To loop over Object Properties:

    You will have to generate an Array of the object properties

    generateArray(obj){
       return Object.keys(obj).map((key)=>{ return obj[key]});
    }
    

    and use it like

    <li *ngFor="let doc of docs">
       <span *ngFor="let v of generateArray(doc)"> {{v}} </span>
    </li>
    

    Or you can use as Pipe.

    0 讨论(0)
提交回复
热议问题