3

I have the following object:

itemList = {
    "0": [],
    "1": [],
    "2": [],
    "3": []
};

I also have the following *ngFor:

<div *ngFor="let new of news; let newindex = index;">
  <div *ngFor="let item of itemList.newindex">
  </div>
</div>

As you can see I'm trying to access itemList[0], for example using the newindex created.

Is this possible?

Roland Rácz
  • 2,879
  • 3
  • 18
  • 44
Manel Alonso
  • 397
  • 3
  • 11

2 Answers2

3

Try to use [] notation to access property

<div *ngFor="let new of news; let newindex = index;">
  <div *ngFor="let item of itemList[newindex]">
  </div>
</div>

Your object is more like to array, so consider to make it as array, not an object with numeric property names.

Check Stackblitz

Suren Srapyan
  • 66,568
  • 14
  • 114
  • 112
0

You need to use the square brackets to get the value of itemList on that parent index newindex

<div *ngFor="let new of news; let newindex = index;">
  <div *ngFor="let item of itemList[newindex]">
  </div>
</div>
Ankit Agarwal
  • 30,378
  • 5
  • 37
  • 62