使用“ where()”时,在AngularFirestore中查询集合不会导致任何数据

时间:2018-11-01 01:41:39

标签: javascript angular firebase google-cloud-firestore angularfire2

我有几个城镇的火力清单。该访问适用于:

 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,那么我不会收到任何错误,但也不会收到任何数据。如果我将类位置更改为接口,则它也是相同的。我什至试图得到

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

但是我无法访问属性或将请求记录到控制台。我觉得我浪费了太多的过时的教程。有人能指出我正确的方向吗,或者有人在MOST RECENT Firebase设置中有棱角英雄的例子吗?

1 个答案:

答案 0 :(得分:3)

尝试这种方式

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

并将其定义为

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

其中 Location 是模型。

相关问题