简体   繁体   中英

ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables Angular 9

hello every one i have this error ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables

i tried.json but it s not working in angular 9

My component.html

  <div class="form-group">
                <label for="">Ville</label>
                <select class="form-control" #hh
                    (change)="getidregion(hh.value)">
                    <option></option>
                    <option *ngFor="let ville of dropDownList"
                        [value]="ville.id">
                        {{ville.nomVille}}
                    </option>

                </select>

            </div>

My Component.TS:

dropDownList: [];

  responsable = {

    id: 0,
    nomResponsable: '',
    prenomResponsable: '',
    emailResponsable: '',
    mdpResponsable: '',
    img: '',
    rib: '',
    dtn: '',
    region: 0,
    ville: 0,
  };

    methodAPIToGetVilles() {
        this.res.getville()
          .subscribe((s: any) => {
            this.dropDownList = s;
    
          });
      }
    
      //methode to get the value off the idville in the option
      getidville(id: any): void {
        this.responsable.ville = id;
    
      }
    
      curUser: any = this.responsable[0];

My API Data:

"@context": "/api/contexts/Ville",
    "@id": "/api/villes",
    "@type": "hydra:Collection",
    "hydra:member": [
        {
            "@id": "/api/villes/6",
            "@type": "Ville",
            "nomVille": "Davidboeuf"
        },
        {
            "@id": "/api/villes/7",
            "@type": "Ville",
            "nomVille": "Benoitboeuf"
        }];

I suppose you are trying to do something like this:

<div *ngFor="let item of object | keyvalue">
  {{item.key}}:{{item.value}}
</div>

This questions is also answered pretty nicely here:

Iterate over object in Angular

How to loop over object properties with ngFor in Angular

If you are using *ngFor , it only supports data is of type array or iterables only.

In your scenario data in your variable dropDownList is either of type object or may be null | undefined. Hence this error occur. Console that data before using it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question Angular error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays Angular 4 : Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays Angular: 'Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays' Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays Ionic 2: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays Angular2 Cannot find a differ supporting object of type 'string'. NgFor only supports binding to Iterables such as Arrays Angular problem: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Array. json data Cannot find a differ supporting object '[object Object]'. NgFor only supports binding to Iterables such as Arrays I keep getting this ERROR: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM