-2

I am trying to loop through multiple arrays inside a json object. Here is a picture of the structure of json object.

enter image description here

I have been trying loop through it using ngFor, but I am getting an error. Here is the code of how I am trying to loop through:

<ion-item *ngFor="let item of items">
{{conversation}}
 </ion-item>

I am getting the following error:

caused by: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.

I need to be able to loop through all the arrays and but I can't figure out how to do that. Any help will be much appreciated.

7
  • This is not an array of arrays but an Object with numeric keys with arrays as properties. How is the original object generated? Commented Apr 4, 2017 at 4:08
  • Original object is generated via a API call, data from that API call is being returned in this format Commented Apr 4, 2017 at 4:12
  • I am pretty sure ng-repeat got replaced with ngfor in angular 2 ? Commented Apr 4, 2017 at 4:17
  • post your JSON here. the way you are accessing the JSON seems wrong. Commented Apr 4, 2017 at 4:30
  • Will you please post the output of objects of json array? Commented Apr 4, 2017 at 4:49

1 Answer 1

2
// in component.ts
data = [];
constructor() {
  for (let item of Object.keys(your_object)) {
    this.data.push(your_object[item]);
  }
}

// in component's template
<ul>
  <li *ngFor="let d of data">
    <span *ngFor="let i of d">{{i}}</data>
  </li>
</ul>
Sign up to request clarification or add additional context in comments.

6 Comments

I tried it out, I get this error caused by: Cannot read property 'keys' of undefined
Validate your json seems something issue with Json
I did Json seems to be fine
Is your json only contaning JSON of arrays or it contains array as well as objects together
It is containing JSON of arrays
|

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.