I am trying to get data from my Firebase using AngularFire2. I want to check specific data, and after I get this data from Firebase, I can check it only in a certain area, and not after the operation with Firebase. Why is this happening?
Below is my code:
this.af.database.list('/users/1qfcMAQnglX9jsW5GdLpPko1HqE2', { preserveSnapshot: true}) .subscribe(snapshots=>{ snapshots.forEach(snapshot => { if(snapshot.key=="reg_boolean"){ console.log(snapshot.val()); this.bo=snapshot.val(); } this.currentUser.push({key:snapshot.key,value:snapshot.val()}); console.log(this.currentUser); //console.log(snapshot.key, snapshot.val()); if(this.bo==true){console.log("happy"); }; //i can access only in this scope }); }) if(this.bo==true){console.log("happy"); }; //why i can access this value??it undefined, this happen before the subscribe with angularfire2

source share