Error: NG0900: Error trying to diff ‘[object Object]’. Only arrays and iterables are allowed

We Are Going To Discuss About Error: NG0900: Error trying to diff ‘[object Object]’. Only arrays and iterables are allowed. So lets Start this Angular Article.

Error: NG0900: Error trying to diff ‘[object Object]’. Only arrays and iterables are allowed

How to solve Error: NG0900: Error trying to diff ‘[object Object]’. Only arrays and iterables are allowed

One thing that is popping up to me is that you’re using the any type.
Doing something in the service like return this.http.get<Cidades[]> would ensure that the response will be parsed to an array of Cidades and might let you know if something goes wrong there. (I can’t remember exactly if it throws if it can’t)
Take a look at Requesting a typed response
Also, use cidades: Cidades[] = []; instead, and you might see where the problem is, when something else is assigned.
Avoid as much as possible to use the type any or you’ll loose all the type safety and strange things might happen.
For instance, if something else that isn’t Cidades[] is assigned to this.cidades the compiler will complain in design time and you can see what’s going on.
Since I didn’t create a project with your code I don’t know exactly what the error is.

Error: NG0900: Error trying to diff ‘[object Object]’. Only arrays and iterables are allowed

One thing that is popping up to me is that you’re using the any type.
Doing something in the service like return this.http.get<Cidades[]> would ensure that the response will be parsed to an array of Cidades and might let you know if something goes wrong there. (I can’t remember exactly if it throws if it can’t)
Take a look at Requesting a typed response
Also, use cidades: Cidades[] = []; instead, and you might see where the problem is, when something else is assigned.
Avoid as much as possible to use the type any or you’ll loose all the type safety and strange things might happen.
For instance, if something else that isn’t Cidades[] is assigned to this.cidades the compiler will complain in design time and you can see what’s going on.
Since I didn’t create a project with your code I don’t know exactly what the error is.

Solution 1

One thing that is popping up to me is that you’re using the any type.

Doing something in the service like return this.http.get<Cidades[]> would ensure that the response will be parsed to an array of Cidades and might let you know if something goes wrong there. (I can’t remember exactly if it throws if it can’t)

Take a look at Requesting a typed response

Also, use cidades: Cidades[] = []; instead, and you might see where the problem is, when something else is assigned.

Avoid as much as possible to use the type any or you’ll loose all the type safety and strange things might happen.

For instance, if something else that isn’t Cidades[] is assigned to this.cidades the compiler will complain in design time and you can see what’s going on.

Since I didn’t create a project with your code I don’t know exactly what the error is.

Original Author rmjoia Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment