Type '{}' is not assignable to type `'any[] | Iterable<any> | (Iterable<any> & any[]) | (any[] & Iterable<any>) | null | undefined'`

Viewed 3074

I am trying to run this code and get an error.

    this.resto.getList().subscribe((result)=>{     
      console.warn(result)
      this.collection=result;
    })

I am getting the error:

core.js:7990 ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.


Type '{}' is not assignable to type 'any[] & Iterable<any>'.
        Type '{}' is not assignable to type 'any[]'.
2 Answers

This solved my problem

collection = <any>{};

You can loop over an object in TypeScript, you can also use this:

collection = <any>[];

collection = <any>{}; worked for me as well as I was facing the same issue. It can be caused due to object mismatch between what is expected and what is returned in the function.

I would also suggest to include "strictPropertyInitialization": false in your tsconfig.json file.

Related