-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.

DN0300
  • 864
  • 2
  • 12
  • 27
  • This is not an array of arrays but an Object with numeric keys with arrays as properties. How is the original object generated? – Explosion Pills Apr 04 '17 at 04:08
  • Original object is generated via a API call, data from that API call is being returned in this format – DN0300 Apr 04 '17 at 04:12
  • I am pretty sure ng-repeat got replaced with ngfor in angular 2 ? – DN0300 Apr 04 '17 at 04:17
  • post your JSON here. the way you are accessing the JSON seems wrong. – Wisely D Cruizer Apr 04 '17 at 04:30
  • Will you please post the output of objects of json array? – Vivek Doshi Apr 04 '17 at 04:49
  • The question doesnt contains full information and even `Duplicate for` http://stackoverflow.com/questions/39819392/cannot-find-a-differ-supporting-object-object-object-of-type-object-ngfor – mayur Apr 04 '17 at 05:01
  • Possible duplicate of [Angular2 - \*ngFor / loop through json object with array](https://stackoverflow.com/questions/43215049/angular2-ngfor-loop-through-json-object-with-array) – Vivek Doshi Feb 06 '18 at 07:24

1 Answers1

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>
David
  • 56
  • 6