如何在Angularfire2中找到某个嵌套对象的长度?
如何查找已完成的项目(待办事项)?在项目列表中如何查找数组中某个对象的长度
<div>Todo List:</div> {{(items | async)?.length}} <-- Total Items in list
<div>{{(items.completed | async)?.length}}</div> <!-- Total completed items? - length of total completed items
<hr>
<ul *ngIf="todo_all">
<li *ngFor="let item of items | async" [class.completed]="item.completed">
{{item.description}}
</li>
</ul>
itemsRef: AngularFireList;
items: Observable<Todo[]>;
constructor(db: AngularFireDatabase) {
this.itemsRef = db.list('todos')
// Use snapshotChanges().map() to store the key
this.items = this.itemsRef.snapshotChanges().map(changes => {
return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }));
});
}