【发布时间】:2023-03-22 12:40:01
【问题描述】:
我正在使用angularfire2 尝试更新我的 Firestore 文档。我有一个参考,我使用 valueChanges 然后订阅以获取数据,但是由于我正在更新函数内部的数据,因此由于值发生变化,它将继续调用它。我想出了一个使用first()from rxjs/operators 的“黑客”解决方案,但是,必须有更好的方法来做到这一点。下面是我试图实现的代码。
this.storeCollectionRef = this.afs.collection('storeInfo');
this.storeDocumentRef= this.storeCollectionRef.doc<StoreInfo>(window.localStorage.getItem("uid"));
this.storeDocumentRef.valueChanges().subscribe(data=>{
console.log(data.itemcount);
var pictures = storage().ref(`${userid}/${data.itemcount+1}`);
pictures.putString(image, "data_url").then(()=>{
pictures.getDownloadURL().then(url => {
this.storeInfo.itemcount = data.itemcount+1;
this.storeInfo.image = url;
this.storeDocumentRef.update(this.storeInfo);
})
});
【问题讨论】:
标签: javascript firebase ionic3 google-cloud-firestore angularfire2