Ad
Obtain Data From QuerySnapshot
I want to obtain data from my cloud firestore. The collection is called 'feedback'. The following code is working
constructor(private fireStore: AngularFirestore) {
this.fireStore.collection('feedback')
.get()
.subscribe((item: firebase.firestore.QuerySnapshot) => {
this.feedbackItems = item.docs.map((dataItem: firebase.firestore.QueryDocumentSnapshot) => dataItem.data());
});
}
with the import
import { AngularFirestore } from '@angular/fire/firestore';
However this.feedbackItems
is now an array of my feedback object from the cloud firestore. Is it possible to obtain the results as an observable?
What is the professional way to obtain the data?
I found several solutions on stackoverflow, however some functions were not available (I guess because a different library or JavaScript is used?)
Ad
Answer
Is it possible to obtain the results as an observable?
You can import map
from the rxjs/operators
to alter the response. You can then assign it to some observable.
this.feedbackItemObservable = this.fireStore.collection('feedback')
.get()
.pipe(map((item:firebase.firestore.QuerySnapshot) => {
return item.docs.map((dataItem: firebase.firestore.QueryDocumentSnapshot) => dataItem.data());
}));
Ad
source: stackoverflow.com
Related Questions
- → .tsx webpack compile fails: Unexpected token <
- → Angular 2 bootstrap function gives error "Argument type AppComponent is not assignable to parameter type Type"
- → AngularJS Two binding in directive
- → How to fix "TS2349: Cannot invoke an expression whose type lacks a call signature"
- → Typescript point to function
- → Manage 301 Redirect when moving oldsite to AngularJS
- → Why is "this" null, in the link function within an Angular Directive?
- → ES6 equivalent of this Angular 2 typescript
- → Where to find example Visual Studio 2015 project(s) using typescript and React?
- → typescript definition for react-router v2.0 - error `has no exported member 'browserHistory'`
- → what version of javascript does typescript compile to?
- → How to configure Visual Studio 2015 to write JSX in ASP.NET 5 (RC) with intellisense
- → what's the different between ///<reference path="..."/> and import statement
Ad