3

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. If I change locationCollection to AngularFirestoreCollection then I get no error but also no data. 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?

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Type 'AngularFirestoreCollection<{}>' is not assignable to type 'Observable<any[]>'. Property '_isScalar' is missing in type 'AngularFirestoreCollection<{}>'. (property) LocationProfilComponent.locationCollection: Observable<any[]>
Thank you so much, of course it is just an Array now. But when I try to log this to console I still get no data. Or just how do I present the data now in the component.html? {{ locationCollection.location_id }}?
you need to map with your model as here github.com/hptumovil/HPTUMovil/blob/…
Oh thank you so much, you have really helped me a lot here. I went through so many tutorials and docs but no answer was up to date or I got way too many error messages to be of use. I own you a soup or something like that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.