1
paymentOptions = 
[
  {
    "key":"COD",
    "value":"COD"
  },
  {
    "key":"ONLINE",
    "value":"ONLINE"
  }
];

I have an array of objects in my component ts file when I loop it in html file using ngFor

<div *ngFor="let obj of paymentOptions">
    <input type="checkbox" value = "{{obj.value}}">{{obj.key}}
</div>

My data print but I get an error in console as Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.

3 Answers3

0
public payngFor=[];

paymentOptions.foreach(element =>{

  payngFor.push(element);

});

and in HTML loop the payngFor it will work.

Nicho
  • 606
  • 1
  • 10
  • 24
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 11 '21 at 07:49
0

Your code should be like below

<div *ngFor="let obj of paymentOptions">
    <input type="checkbox" [value]="obj.value">{{obj.key}}
</div>

For more details refer below links binding-syntax, interpolation, template-statements

KEVAL PANCHAL
  • 535
  • 3
  • 14
0

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

Your provided code doesnt reproduce the error. I assume there is another loop in your template trying to Iterate over incompatible data type.

Reason for this error is basically you are trying iterate over a string, object or any other sort of data type rather than the type being an array. It gets thrown from template where you are using *ngFor.

Please refer to sample stackblitz code snipet here

Selaka Nanayakkara
  • 3,296
  • 1
  • 22
  • 42