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?

2
  • Possible duplicate of Object property name as number Commented Apr 10, 2018 at 12:55
  • use $index instead of index Commented Apr 10, 2018 at 12:55

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

4 Comments

Not working, note that i have an object (itemList), and i'm printing the object and it has values on the arrays...
Have you checked the example ?
Yes, and replicated like that. Note that I'm updating itemList values dinamically, does it have something to do with the problem?
So it was basically an error of mine, i was missing an "x" on "index"... But i was missing the "[ ]" so thanks for that. :)
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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.