0

I am having this object:

protected products: { 
 [key: string]: {
  color: string,
  brand: string,
 };
} = {};

products =  {
 scan12345: {color: "Orange", brand: "X"},
 scan13813: {color: "Pink", brand: "X"},
}

How can I iterate through this project in my component Tempate? I tried:

<ion-item *ngFor="let pro of products">
   {{ pro.color }}
</ion-item>
Kathrine Hanson
  • 575
  • 2
  • 10
  • 32

1 Answers1

2

You can use the KeyValuePipe:

<ion-item *ngFor="let pro of products | keyvalue">
   {{ pro.value.color }}
</ion-item>

Documentation: https://angular.io/api/common/KeyValuePipe

József Cserkó
  • 299
  • 2
  • 9