使用 "where()" 时,在 AngularFirestore 中查询 Collection 结果没有数据
Querying Collection in AngularFirestore results in no data when using "where()"
我在几个城镇的 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,那么我不会收到任何错误,但也不会收到任何数据。如果我将 class 位置更改为接口,它也是一样的。我什至试图得到
this.location = db.doc('/Locations/' + townname);
但我无法访问属性或将请求记录到控制台。我觉得我在太多过时的教程上浪费了时间。谁能给我指明正确的方向,或者谁有 angular 英雄示例和最新的 firebase 设置?
试试这个方法
this.locationCollection = this.db.collection('Locations', ref => ref.where('location_id', '==', 'Townname')
并将其定义为,
locations: Array<any>;
locationCollection: AngularFirestoreCollection<Location>;
其中 Location
是模型。
我在几个城镇的 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,那么我不会收到任何错误,但也不会收到任何数据。如果我将 class 位置更改为接口,它也是一样的。我什至试图得到
this.location = db.doc('/Locations/' + townname);
但我无法访问属性或将请求记录到控制台。我觉得我在太多过时的教程上浪费了时间。谁能给我指明正确的方向,或者谁有 angular 英雄示例和最新的 firebase 设置?
试试这个方法
this.locationCollection = this.db.collection('Locations', ref => ref.where('location_id', '==', 'Townname')
并将其定义为,
locations: Array<any>;
locationCollection: AngularFirestoreCollection<Location>;
其中 Location
是模型。