It seems that I'm facing an issue with retrieving the element value inside a typescript foreach loop.
constructor(db: AngularFireDatabase) {
}
this.fbUserData = this.db.list('users/'+this.userid).valueChanges()
this.fbUserData.forEach(element => {
this.currentRole = element[2].toString(); // receive value
})
Now, when attempting to retrieve the value from AngularFireBase outside the loop, I encountered the following problem:
this.userid = this.firebaseAuth.auth.currentUser.uid.toString();
this.fbUserData = this.db.list('users/'+this.userid).valueChanges()
this.fbUserData.forEach(element => {
this.rolelist.push(element[2].toString());
})
Unfortunately, the 'rolelist' array remains empty outside the loop, even though it receives values like ['test'] inside the loop.
I aim to log 'rolelist' outside the loop using the following function:
checkAuth(data){
this.userid = this.firebaseAuth.auth.currentUser.uid.toString();
this.fbUserData = this.db.list('users/'+this.userid).valueChanges()
this.fbUserData.forEach(element => {
this.rolelist.push(element[2].toString());
})
console.log(this.rolelist);
This way, 'rolelist' should contain the element value obtained from the foreach loop.