如何在Angularfire2中获取某些嵌套对象的长度?

时间:2018-01-13 10:22:11

标签: firebase firebase-realtime-database angularfire angular5

如何在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() }));
});
}

0 个答案:

没有答案