I am trying to pull data from firebase just once. With this code it subscribes and watches for changes and updates value realtime.
this.profileData = this.fire.authState.switchMap(auth => this.db.object(`profile/${auth.uid}`).snapshotChanges().map(action => {
const $key = action.payload.key;
const data = { $key, ...action.payload.val() };
return data;
})).subscribe(profile => {
this.profileData = profile;
console.log(this.profileData.username); // this is working.
});
I was trying something like this but its not working
this.profileData = this.fire.authState.switchMap(auth => this.db.object(`profile/${auth.uid}`)).take(1).subscribe(profile =>{
console.log(profile.username);
}));