[英]Ionic3, angular & firebase get from db
在聊天應用程序上工作。 將消息推送到數據庫工作正常,但獲取查詢似乎無效。
ts文件看起來像這樣,將消息發送到db即可正常工作。 獲取消息不起作用。
ngOnInit(){
this.encryptedMessages = this.getMessage();
}
getMessage(){
return this.db.list('/messenger');
}
sendMessage(){
this.db.list("/messenger").push({
username: this.username,
message: this.message
}).then(()=>{
//what happens once message is sent
});
}
html看起來像這樣。 使用* ngFor和異步管道顯示從數據庫檢索到的所有消息。 屏幕上沒有任何內容
<ion-content padding>
<div id="message" *ngFor="let m of encryptedMessages | async">
<div class="username">{{ m.username }}</div>
<div class="message"> {{ m.message }} </div>
</div>
</ion-content>
您還可以訂閱到您的列表。
ngOnInit(){
this.getMessage().snapshotChanges()
.subscribe((actions) => {
this.encryptedMessages = actions.map((action) => {
const data = action.payload.val();
data.key = action.key;
return data;
});
});
}
getMessage(){
return this.db.list('/messenger');
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.