我正在尝试在我的* ngFor元素中检查子项的长度。我从firebase实时数据库中读取数据。哪里错了?
我的代码:
<div *ngFor="let event of events">
<div>Eventname:{{event.name}} </div>
<div> Amount of Arrival: {{event.arrival.length}} </div>
</div>
我的DB:
Event{
a{
date: "12,Nov"
name: "best event"
arrival:{
a{
name:"david",
from:"USA"
}
b{
name:"Mike",
from:"GER"
}
}
}
}
我的服务:
getDataList(listpath:string){
this.itemsRef = this.db.list(listpath);
this.items = this.itemsRef.snapshotChanges().pipe(
map(changes =>
changes.map(c => ({ key: c.payload.key, ...c.payload.val() }))
)
);
return this.items;
}
我的组件:
this.db.getDataList("/Event/" ).subscribe(res => {
this.events=res;
});
event Arrival现在是对象,如果你可以将它改为Array,那么你可以使用length。 {} - object,[] - array。祝好运!