更新时间:2022-05-07 00:07:19
AngularFire中没有任何内置功能可用于检测节点存在。但由于AngularFire是基于Firebase JavaScript SDK构建的,因此您可以使用JavaScript API执行此操作:
There is nothing built into AngularFire for detecting if a node exists. But since AngularFire is built on top of the Firebase JavaScript SDK, you can do this with the JavaScript API:
ref.child(uid).once('value', function(snapshot) {
console.log(snapshot.exists());
});
要实现的重要一点是此代码段使用值
event,如果当前位置没有数据,将触发 null
。
The important thing to realize is that this snippet uses a value
event, which will fire null
if there is no data at the current location.
A $ firebaseArray()使用Firebase的 child _ *
事件,这些事件不能用于检测是否存在集合中的特定孩子。
A $firebaseArray()
from AngularFire on the other hand uses Firebase's child_*
events, which cannot be used to detect existence of a specific child in the collection.