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\",
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;
})
}