【发布时间】:2018-01-10 09:55:21
【问题描述】:
如何计算已完成项目的总长度?
如何查找已完成的总项目(待办事项)?在项目列表中 如何在数组中找到某个对象的长度
<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() }));
});
}
【问题讨论】:
标签: angular firebase firebase-realtime-database angularfire2 angular5