1

I have a hashed map object that the key is a string representing a class number and the value for each key is an Arraylist of Student object so in general the object that I want to iterate through is of type: Map<String,Arraylist<Student>> I want to display a tree like structure of the object values, I tried to use :

<div *ngFor="let key of MyObject">{{key}} </div> But this shows only the class number but it does not show the students names in each class. does anyone know how to iterate through each key and each object inside that key?

4
  • JavaScript doesn't use Java objects. Post the structure of the JavaScript object/array that you want to iterate on. Commented Feb 26, 2017 at 16:14
  • In F12 it looks like this: MyObject >"Classe123">[{Name:"Student1",Marks:20},{Name:"Student2",Marks:60}] and then there is another class under "Classe123" > "Classe998">[{Name:"Student3",Marks:70},{Name:"Student4",Marks:10}] Commented Feb 26, 2017 at 16:16
  • Execute console.log(JSON.stringify(myObject)), and post the result.Post it in your question, not in a comment. Commented Feb 26, 2017 at 16:21
  • Make use of pipes it will solve your issue Commented Feb 26, 2017 at 17:09

1 Answer 1

1

You should create another *ngFor to iterate through the arrayList

<div *ngFor="let key of MyObject"> Class {{key}}
  Students:
  <div *ngFor="let student of MyObject.get(key)">
    {{student.name}}
  </div> 
</div>

this way it should display each class and each student in that class.

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

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.