You can handle like this.
array: any[] = [];
ngOnInit() {
// this.array = []; //no need to set this empty array here
// will go inside only if required array is empty
if (!this.array || !this.array.length) {
// 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);
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…