javascript - 使用 "where()"时,在 AngularFirestore 中查询集合导致没有数据

标签 javascript angular firebase google-cloud-firestore angularfire2

我有几个城镇位置的 Firebase 列表。访问适用于:

 public locations: Observable<any[]>;
 constructor(db: AngularFirestore) {
 this.locations = db.collection('/Locations').valueChanges();}

然后我可以访问所有位置的数据:

 {{ location.location_id }} etc

现在我想在下一页访问一个特定城镇的所有位置。

this.locationCollection = db.collection('/Locations', ref =>
ref.where('location_id', '==', 'Townname'));

但它不可赋值或_scalar。如果我将 locationCollection 更改为 AngularFirestoreCollection,那么我不会收到任何错误,但也不会收到任何数据。如果我将类位置更改为接口(interface),它也是一样的。我什至试图得到

this.location = db.doc('/Locations/' + townname);

但我无法访问属性或将请求记录到控制台。我觉得我在太多过时的教程上浪费了时间。谁能指出我正确的方向,或者谁有最新的 firebase 设置的 Angular 英雄示例?

最佳答案

试试这个

this.locationCollection = this.db.collection('Locations', ref => ref.where('location_id', '==', 'Townname')

并将其定义为,

 locations: Array<any>;
 locationCollection: AngularFirestoreCollection<Location>;

其中 Location 是模型。

关于javascript - 使用 "where()"时,在 AngularFirestore 中查询集合导致没有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53094135/

相关文章:

javascript - 为什么在 js 中运行两个单独的循环与运行单个 for 循环之间存在性能差异

javascript - 电子邮件不会发送 Angular 4 和 PHP

ios - firebase 是否需要代码来刷新身份验证?

java - DatabaseException : can't convert object of java. Lang.String 要键入

javascript - 组合框没有在加载时设置合适的值,而是空白

javascript - jQuery 图像交换 - chrome 中的奇怪行为

javascript - 将 div 设置回显示时出现问题 :none after setting it to block

java - Http错误响应: internal server error

Angular CLI 获取当前使用的端口

json - 使用 Swift 在 Firebase 中保存现有的 JSON 文件?