I attempted to generate an auto document ID in Firestore and retrieve the document ID in Angular 8 using the code provided. However, I am encountering an issue where I only receive the document ID after the execution has been completed. Can someone please assist me with this? Thank you in advance.
this.db.collection("testdata2").add({
"name": "Tokyo",
"country": "Japan",
"Date": this.date
})
.then(function(docRef){
component.docid=docRef.id;
console.log("Document written with ID: ", docRef.id);
})
.catch(function(error) {
console.error("Error adding document: ", error);
});
console.log(component.docid);