我有几个城镇位置的 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/