I am trying to get some Document data from Firestore, which I have found easy enough to do. But how can I then make that data available to other functions? Here's my code:
let documentRef = this.afs.collection('profiles').doc(this.userId);
var myProfileRef = documentRef.ref.get()
.then(doc => {
this.myFirstName = doc.data().firstName;
console.log(this.myFirstName)
})
console.log(this.myFirstName)
The first time I try to log the name, it works. But outside of the }) I get 'undefined' and I cannot use this.myFirstName
anywhere outside of this. What am I missing?
EDIT: It seems to me as though this problem lies in the asynchronous nature of working with Firestore data. So I guess I'm asking if there's an asynchronous way to pull this data?