简体   繁体   English

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

[英]Querying Collection in AngularFirestore results in no data when using “where()”

I have a list on firebase of locations in several towns. 我列出了几个城镇的火灾基地名单。 The access works with: 访问适用于:

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

Then I can access the data of all locations with: 然后我可以访问所有位置的数据:

 {{ location.location_id }} etc

Now I want to access all locations in one specific town in the next page. 现在,我想访问下一页中某个特定城镇的所有位置。

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

But it is not assignable or _scalar. 但它不是可分配的或_scalar。 If I change locationCollection to AngularFirestoreCollection then I get no error but also no data. 如果我将locationCollection更改为AngularFirestoreCollection,那么我没有错误但也没有数据。 If I change the class location to an interface it is also the same. 如果我将类位置更改为接口,它也是相同的。 I even tried to get 我甚至试图得到

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

But I cannot access the attributes or log the request to console. 但我无法访问属性或将请求记录到控制台。 I feel like I have wasted my time with too many obsolete tutorials. 我觉得我浪费了我太多过时教程的时间。 Could anyone point me into the right direction or does anyone have the angular heroes example with the MOST RECENT firebase setup? 任何人都可以指出我正确的方向或有没有任何角度英雄的例子与MOST最近的firebase设置?

Try this way 试试这种方式

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

and define it as, 并将其定义为

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

where Location is the model. 其中Location是模型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM