I have a page to a retrieve user's information, but I am getting undefined.
Below is my data structure
{
"posts" : {
"-L4QKxs6d06Vq3amQ7C8" : {
"content" : "Test",
"owner" : "D5hkgRIN87OUr3rdSGK1Znws1aB2",
"title" : "Admin Post"
},
"-L4UDg1_glHcqwGjGpTQ" : {
"content" : "fsdfd",
"owner" : "D5hkgRIN87OUr3rdSGK1Znws1aB2",
"title" : "rewsrwr"
}
},
"users" : {
"D5hkgRIN87OUr3rdSGK1Znws1aB2" : {
"posts" : {
"-L4QKxs6d06Vq3amQ7C8" : {
"title" : "Admin post"
},
"-L4UDg1_glHcqwGjGpTQ" : {
"title" : "rewsrwr"
},
"-L4UDj1vKnTpogjZ26Zg" : {
"title" : "sdfsdf"
}
},
"role" : "0",
"username" : "Admin"
}
}
}
profile.ts
export class ProfilePage {
currentUser = firebase.auth().currentUser;
user: Observable<User[]>;
constructor(public navCtrl: NavController, private db: AngularFireDatabase) {
this.user = this.db.list(`/users/${this.currentUser.uid}`).snapshotChanges()
.map(actions => {
return actions.map(action => {
return { key: action.key, ...action.payload.val() };
});
});
console.log(this.user.username);
}
}
- "angularfire2": "5.0.0-rc.4",
- "firebase": "4.8.2",
Am I doing something wrong here?
I finally figured it out! took some hints from angularfire2 issue#396
profile.ts
Or you can use it in your template without subscribe
Try changing the
part to