![](/img/trans.png)
[英]How to read data from Firebase Real Time database with React Native?
[英]how to receive data from real time database in firebase in angular
試試這個從firestore獲取消息列表。 導入AngularFireDatabase服務和AngularFireList來存儲消息集合。
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(); } }
確保您已在應用模塊中導入AngularFireModule和AngularFireDatabaseModule 。
AngularFire 是通過 RxJs 庫使用可觀察模式構建的。
您可以使用 valueChanges() 方法 stream 數據,如文檔中所述
items: Observable<any[]>;
constructor(firestore: AngularFirestore) {
this.items = firestore.collection('items').valueChanges();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.