I'm new to angular/firestore/ionic. I know the following code is bad, but I'm not sure how to improve it. I tried using awaits ... then I tried "callbacks" but couldn't seem to figure it out. I'm not sure if there is an issue with it being specific to typescript, angular 8 or ionic. Sorry if this is a duplicate question but I really need clarification if possible.
I tried following Call multiple async methods that rely on each other but it's in c# and I found Running function with async method in sequential order confusing to be honest.
constructor(public modalController: ModalController,private crudService: CrudService, public afAuth: AngularFireAuth, private db: AngularFirestore) {
setTimeout( () => {this.currentUserID = this.afAuth.auth.currentUser.uid}, 1000)
setTimeout( () =>{
var docRef = db.collection('users').doc(this.currentUserID);
docRef.snapshotChanges().subscribe(data => {
console.log(data.payload.data()['selectedDate'])
this.selDate = data.payload.data()['selectedDate']
})
}, 2000)
setTimeout( () =>{
var docRef = db.collection('users').doc(this.currentUserID);
docRef.snapshotChanges().subscribe(data => {
console.log(data.payload.data()['selectedEx'])
this.selEx = data.payload.data()['selectedEx']
})
}, 3000)
setTimeout(() =>{
var getSetsRef = db.collection('users').doc(this.currentUserID).collection('dates').doc(this.selDate).collection('userExercises').doc(this.selEx);
getSetsRef.snapshotChanges().subscribe(data => {
console.log(data.payload.data()['sets'])
this.sets = data.payload.data()['sets']
})
}, 4000)
}