I am getting Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
error while I am trying to print all of my database records.
I have used this source to get the data from firebase. Somehow it does not work. Is my json file structure wrong or the type of the array should be different? What I am doing wrong?
firebase (json)
{
"clients" : {
"-L4jvQwBFM0W8A928waj" : {
"id" : "124",
"lastName" : "sda421",
"name" : "412"
},
"-L4jz52GfcU4ZsJx_LX0" : {
"id" : "214",
"lastName" : "sda ",
"name" : "sad "
},
"-L4k-5xNmN4dalqFj2dB" : {
"id" : "12345678",
"lastName" : "Pafasfbin",
"name" : "fasf"
},
"-L4k-Dw5TA6FnHpWDiIq" : {
"id" : "52353235",
"lastName" : "qweqw",
"name" : "qwrqwe "
}
}
}
clients.component.ts
import { Component, OnInit } from '@angular/core';
import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabase } from 'angularfire2/database' ;
import { Observable } from 'rxjs';
@Component({
selector: 'app-clients',
templateUrl: './clients.component.html',
styleUrls: ['./clients.component.css']
})
export class ClientsComponent implements OnInit {
// clients: any[];
clients: Observable<any[]>;
name: string;
lastName: string;
id: number;
constructor(public db: AngularFireDatabase) { }
ngOnInit() {
this.getData();
}
getData(){
this.clients = this.db.list('/clients').valueChanges();
console.log(this.clients);
}
}
clients.component.html
<ul>
<li *ngFor="let i of clients">
<label>name: </label> {{ i.name }}
<label>lastName: </label> {{ i.lastName }}
<label>ID: </label> {{ i.id }}
</li>
</ul>