1

I need to iterate Object of array of objects in anchor tag. Following is the format of my code

{"1":{"uri":"test1","name":"test1","icon":"http:\/\/dummyurl\/images\/icons\/test1-icon.png","application_id":1},"2":{"uri":"test2","name":"test2","icon":"http:\/\/dummyurl\/images\/icons\/test2-icon.png","application_id":2},"3":{"uri":"test3","name":"test3","icon":"http:\/\/dummyurl\/images\/icons\/test3-icon.png","application_id":3},"4":{"uri":"test4","name":"test4","icon":"http:\/\/dummyurl\/images\/icons\/test4-icon.gif","application_id":4},"5":{"uri":"test5","name":"test5","icon":"http:\/\/dummyurl\/images\/icons\/test5-icon.png","application_id":5}}

.ts file

this.applicationService.getApplication(id)
    .subscribe(applications => {
    this.applications = applications.response;});

html

<a class="dropdown-item" href="#" NgForOf=" let obj of applications">
    {{obj.name}} </a>

I am stuck in this from last 3-4 hours. Any help will be appreciated.

2
  • 2
    Take the time to format your code and question correctly before posting. Also, you have not explained what is not working with the code you posted or what you did to solve it or what your exact confusion is. Commented Aug 10, 2017 at 13:56
  • The keys are consecutive numbers? Commented Aug 10, 2017 at 14:02

1 Answer 1

1

You can loop through them using Object.keys(apps)

this.applicationService.getApplication(id)
  .map(result => result.response)
  .subscribe(apps=> {
    this.applications = Object.keys(apps).map(k => apps[k])
   });

HTML

<div *ngFor="let app of applications">{{app | json}}</div>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much @KId. You not only saved my time. You saved me also :) I was looking for this quick and short answer.

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.