Angular / Firestore - ' Where'在AngularFirestoreCollection'

时间:2018-02-28 09:54:34

标签: javascript angular firebase firebase-realtime-database google-cloud-firestore

我试图根据传递给参数的URL参数从firestore集合中获取特定文档,但是当我使用expensesCollection: AngularFirestoreCollection<Expense>初始化集合时,{{ 1}}查询返回以下错误:

  

TS2339:财产&#39;其中&#39;类型&#39; AngularFirestoreCollection

上不存在

&#39; ViewExpense&#39;单击&#39; ExpensesList&#39;上的数据表行后访问组件。 component,它将费用ID作为参数传递,该参数在where查询中使用。

-

费用-list.component.html:

where

-

查看-expense.component.ts:

<mat-row *matRowDef="let row; columns: tableColumns" routerLink="/expenses/view/{{row.expenseId}}"></mat-row>

1 个答案:

答案 0 :(得分:14)

where中没有AngularFirestoreCollection函数,而是应该在collection()的第二个参数中提供where条件,如下所示:

this.expensesCollection = this.db.collection('/expenses', ref => ref.where(expenseId', '==', this.expenseId));

参考:https://github.com/angular/angularfire2/blob/master/docs/firestore/querying-collections.md