for some reason I cannot receive the given element value inside the 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 outside the loop I want to receive the value from the AngularFireBase I tried the following:
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());
})
but this.rolelist (array) remains empty outside the loop. inside the loop it will receive the value like array ['test']
I want it to console.log outside the loop like this:
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);
so that this.rolelist has the element value from the foreach loop