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

后端 未结 18 1229
逝去的感伤
逝去的感伤 2020-11-29 05:50

I looked at similar questions, but none of them helped me. I am going to receive an object like the following:

[
  {
    \"id\": 1,
    \"name\": \"Safa\",
          


        
18条回答
  •  长情又很酷
    2020-11-29 06:26

    Here is the solution.

    When you are receiving array from your database. and you are storing array data inside a variable but the variable defined as object. This time you will get the error.

    I am receiving array from database and I'm stroing that array inside a variable 'bannersliders'. 'bannersliders' type is now 'any' but if you write 'bannersliders' is an object. Like bannersliders:any={}. So this time you are storing array data inside object type variable. So you find that error.

    So you have to write variable like 'bannersliders:any;' or 'bannersliders:any=[]'.

    Here I am giving an example.

    
    bannersliders:any;
      getallbanner(){
        this.bannerService.getallbanner().subscribe(data=>{
          this.bannersliders =data;
       })
      }

提交回复
热议问题