angular firestore 中有 .get() 吗?
Is there a .get() in angular firestore?
我看到有 .valueChanges() 和 .snapshotChanges() 都监听数据库中的更改,但是如果我只想检索一次数据怎么办?
我注意到在 .valueChanges() 或 .snapshotChanges() 的末尾添加 .pipe(take(1)) 是有效的,但它是否与 firebase firestore 在 admin sdk 和 mobile sdk 中为 [= 提供的 .get() 函数相同21=] 和 iOS?
我在做什么
this.items = this.itemCollection.valueChanges().pipe(take(1));
我期待什么
this.items = this.itemCollection.get();
PS: 我是新手
非反应方式
如果您正在寻找一种不使用 React 的方法,您可以在 ref 而不是集合项上调用 get() 方法。
this.itemCollection.ref.get().then((querySnap) => {
//use your data here
console.log(querySnap.docs);
});
React 方式
this.itemCollection.get() returns 您可以订阅的 QuerySnapshot 类型的可观察对象
this.itemCollection.get().subscribe((querySnap) => {
console.log(querySnap.docs)
});
我看到有 .valueChanges() 和 .snapshotChanges() 都监听数据库中的更改,但是如果我只想检索一次数据怎么办? 我注意到在 .valueChanges() 或 .snapshotChanges() 的末尾添加 .pipe(take(1)) 是有效的,但它是否与 firebase firestore 在 admin sdk 和 mobile sdk 中为 [= 提供的 .get() 函数相同21=] 和 iOS?
我在做什么
this.items = this.itemCollection.valueChanges().pipe(take(1));
我期待什么
this.items = this.itemCollection.get();
PS: 我是新手
非反应方式
如果您正在寻找一种不使用 React 的方法,您可以在 ref 而不是集合项上调用 get() 方法。
this.itemCollection.ref.get().then((querySnap) => {
//use your data here
console.log(querySnap.docs);
});
React 方式
this.itemCollection.get() returns 您可以订阅的 QuerySnapshot 类型的可观察对象
this.itemCollection.get().subscribe((querySnap) => {
console.log(querySnap.docs)
});