Try this to get the messages list from the firestore. Import AngularFireDatabase service and AngularFireList to store message collection.
import { Injectable } from '@angular/core'; import { AngularFireDatabase, AngularFireList } from '@angular/fire/database'; @Injectable({ providedIn: 'root' }) export class MessageService { messages: AngularFireList<any>; constructor(private http: HttpClient, private db: AngularFireDatabase) { } /** * Get All tickers from firebase */ getMessages(): Observable<any> { this.messages = this.db.list('messages'); return this.messages.valueChanges(); } }
Make sure you have imported AngularFireModule and AngularFireDatabaseModule in your app module.
AngularFire is build with the Observable Pattern via RxJs Library.
You can stream the data with the valueChanges() method, as described in the documentation
items: Observable<any[]>;
constructor(firestore: AngularFirestore) {
this.items = firestore.collection('items').valueChanges();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.