0
我在角度/離子2中使用firebase,並且需要檢查值是否存在以及如果不存在,則創建它但firebase不會返回null在docs狀態和我的支票沒有運行,因爲它。firebase .on值在不存在數據時不會返回null
subscribeToOffer(uid, offerID) {
var path = 'users/' + uid + '/offers/' + offerID;
this.rootRef.child(path).on('value', subscribed => {
if (subscribed.val() !== null) {
console.log('subscribed');
} else {
console.log('not subscribed');
}
});
}
如果它不返回null那麼它返回什麼?你確定這條路是正確的嗎?也許在你的問題中添加你正在使用的數據的樣本(作爲文本,而不是圖片) –
它根本不會返回,沒有任何反應。路徑是正確的,因爲當報價存在時,它會運行,但是當它不是什麼都不做時,我需要返回執行我的else語句。 – Lindstrom
你有沒有試過這個:https://www.firebase.com/docs/web/api/datasnapshot/exists.html –