Ad
Firestore ValueChanges() Only Emits Once When Using Take(1)
I have a document called booking
in the counts
collection (counts/booking
) of my firestore database. I want to read data from this booking document and listen for value changes too. How can I achieve this using AngularFire2?
I have tried the following code,
this.afs.collection('counts').doc<Count>('booking').valueChanges().pipe(take(1))
.subscribe(data => {
if (data) {
this.newCount = data.newCount;
this.otherCount = data.otherCount;
}
});
This reads the value but doesn't seem to update the values as it changes in the firestore document.
Ad
Answer
Remove the take(1)
pipeable operator as this will cause your code to effectively only execute/emit a single (1) time:
this.afs.collection('counts').doc<Count>('booking').valueChanges()
.subscribe(data => {
if (data) {
this.newCount = data.newCount;
this.otherCount = data.otherCount;
}
});
Hopefully that helps!
Ad
source: stackoverflow.com
Related Questions
- → Make a Laravel collection into angular array (octobercms)
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → Angularjs not working inside laravel form
- → Analysis of Flux implementations
- → how to write react component to construct HTML DOM
- → angular ng-repeat and images in a row
- → Conditional BG Color on AngularJS
- → Should I 'use strict' for every single javascript function I write?
- → getting the correct record in Angular with a json feed and passed data
- → "Undefined is not a function" at .toBe fucntion
- → angularjs data binding issue
- → Angular / JavaScript auto hydrate an instance
- → Convert generic text string in json object into valid url using Angular
Ad