1

I have my servers.service.ts that does a GET REQUEST this:

  getServers(){
     return this.http.get('https://*******.firebaseio.com/data.json').map((response: Response)=>{const data=response.json();console.log(data);return data;});
}

And in my app.component.ts I do this:

onGet(){
    this.serverService.getServers().subscribe(
      (servers: any[])=> this.servers=servers,
      (error)=>console.log(error)
    );
  }

I use like db firebase and it throws this exception

Error trying to diff '[object Object]'. Only arrays and iterables are allowed

when I call onGet(). Anyone can help me?

1

1 Answer 1

1

ngFor only accept array format data. But your service returning non array object.that's the reason for why you are getting this error.

Try this below code

const data=response.json().results;

instead of

 const data=response.json()
Sign up to request clarification or add additional context in comments.

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.