1

I got data like this in my console from my API:

[
    {
        id:"123",
        name:"asd",
        address:"st.dddss",
        status:1
    }
]

I call it using ngFor and I got this error:

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

But that still works and data is showing. This is my code:

this._service
    .getHotelbyId(this.id)
    .subscribe(hotel =>
        {
          this.Hotels = hotel
          console.log(this.Hotels);
        },
        error =>
        {
            console.log(error);
        })

And I call it like this using *ngFor

*ngFor="let z of Hotels

{{z.name}} , {{z.address}}

How to solve that error message?

3
  • console.log(this.Hotels - what is the output? Commented Feb 2, 2018 at 16:57
  • i got this [{id:"123",name:"asd",address:"st.dddss",status:1}] Commented Feb 2, 2018 at 17:00
  • {{ Hotels | json }} - try this and what's the output.? Commented Feb 2, 2018 at 17:12

2 Answers 2

0

I believe this error is because you assigned the JSON string response you obtained from your api to this.Hotels.

You need to parse the JSON string as your Javascript object. Try this.

this.Hotels = JSON.parse(hotel)

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

0

problem solved just remove ngFor and use index of array like this Hotels[0].name link

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.