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 –