【发布时间】:2021-01-27 21:36:25
【问题描述】:
我的项目中目前存在一个错误,我的 Firebase 查询被多次执行。这个问题在我的整个开发过程中都没有出现,并且与 Firebase 依赖项等相关的任何内容都没有改变
这是一段代码示例,过去只执行一次,但现在执行多次
ngOnInit(): void {
this.array = [];
// Try-Catch function reading data from Firestore
try {
this.db.collection("myCollection").where("Age", "==", "20").onSnapshot(snapshot => {
snapshot.docs.forEach (() => {
this.db.collection('Jobs').get().then (snapshot2 => {
snapshot2.docs.forEach (snapshot3 => {
if (snapshot3.id.includes('Unemployed')){
this.array.push(
{
ID: snapshot3.id
}
);
}
})
})
})
})
} catch (error) {
console.log(error.message);
}
}
提前感谢您的帮助
【问题讨论】:
标签: javascript angular typescript firebase