I have a problem with a promise. I have this function that is used to comunicate with Firestore database:
async getDataFromDB() {
const junctionRef = firebase
.firestore()
.collection('junction')
.doc(this.id)
.collection('items')
.doc(this.userId);
return await junctionRef.get().then((doc) => {
const details = doc.data();
return details;
});
}
In ngOnInit method I call this funtion and, based on the result of this promise, I want to set some values:
ngOnInit() {
....
this.getDataFromDB().then((data) => {
if(data != null && data.numbers<10 )
// TO SOMETHING
});
But it never enters the if because data tells me it is undefined . How can I solve it ?