[英]angular ngFor how to get child length
I'm trying to do Check length of child in my *ngFor element. 我正在尝试在我的* ngFor元素中检查子项的长度。 I read data from a firebase real-time database.
我从firebase实时数据库中读取数据。 where I am wrong?
哪里错了?
this my code: 我的代码:
<div *ngFor="let event of events">
<div>Eventname:{{event.name}} </div>
<div> Amount of Arrival: {{event.arrival.length}} </div>
</div>
this my DB: 我的DB:
Event{
a{
date: "12,Nov"
name: "best event"
arrival:{
a{
name:"david",
from:"USA"
}
b{
name:"Mike",
from:"GER"
}
}
}
}
this my service: 我的服务:
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 my component: 我的组件:
this.db.getDataList("/Event/" ).subscribe(res => {
this.events=res;
});
event Arrival is now object, if you can change it to Array, then you can use length. event Arrival现在是对象,如果你可以将它改为Array,那么你可以使用length。 {} - object, [] - array.
{} - object,[] - array。 Good luck!
祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.