I am working on retrieving data from my Firebase User List using the following code:
currentUserRef: AngularFireList<any>
currentUser: Observable<any>;
var user = firebase.auth().currentUser;
this.currentUserRef = this.af.list('usuarios', ref =>
ref.orderByChild('email').equalTo(user.email));
this.currentUser = this.currentUserRef.valueChanges();
this.currentUser.subscribe(res => console.log(res[0].condominio));
The retrieved data contains two properties: 'condominio' and 'email'.
After displaying the data in the console with `console.log(res[0].condominio)`, I need to store it in a variable like this:
userCond: string;
However, when I try to assign the 'condominio' property from 'res' to 'userCond', it doesn't seem to work:
this.currentUser.subscribe((res) => { this.userCond = res[0].condominio });
What could be going wrong here?
"angularfire2": "^5.0.0-rc.11",
"firebase": "^5.3.1",
"ionic-angular": "3.9.2",
EDIT:
export class HomePage {
currentUserRef: AngularFireList<any>
currentUser: Observable<any>;
moradorRef: AngularFireList<any>
morador: Observable<any>;
userCond: string;
constructor(
public authService: AuthService,
public userService: UserService,
public navCtrl: NavController,
public navParams: NavParams,
public af: AngularFireDatabase
) {
}
ionViewCanEnter(): Promise<boolean> {
return this.authService.authenticated;
}
ionViewDidLoad(){
debugger;
//TRAZ AS MESMAS INFORMAÇÕES
//this.userService.getCurrentUser();
var user = firebase.auth().currentUser;
//const _this = this;
this.currentUserRef = this.af.list('usuarios', ref =>
ref.orderByChild('email').equalTo(user.email));
this.currentUser = this.currentUserRef.valueChanges();
//this.currentUser.subscribe(res =>
console.log(res[0].condominio));
this.currentUser.subscribe(res => {
debugger;
this.userCond = res[0].condominio;
});
console.log(this.userCond);