profile.page.ts:
username: string;
totalScore: number;
...
loadUserData() {
this.spinnerDialog.show();
this.firebaseServie.loadUserData().then(() => {
this.username = this.sessionData.getUser().getUsername();
this.totalScore = this.sessionData.getUser().getTotalScore();
....
});
firebase.service.ts
:
async loadUserData() {
console.log(this.sessionData.getUser().getEmail());
this.userCollection = this.afs.collection('users', ref => ref.where('email', '==', this.sessionData.getUser().getEmail().toLowerCase()));
this.userDoc = this.afs.collection("users").doc(this.sessionData.getUser().getEmail().toLowerCase());
this.x = this.userDoc.valueChanges().subscribe(((item: User) => {
this.userLoadedUser = item;
console.log("Found user by email id " + this.sessionData.getUser().getEmail() + ":" + this.userLoadedUser.username);
this.sessionData.getUser().setUsername(this.userLoadedUser.username);
this.sessionData.getUser().setTotalScore(this.userLoadedUser.totalScore);
....
}));
}
How can I ensure that the code within the then()
block is only executed once we have received the data from Firebase?
I made revisions to my question to enhance clarity.