0
votes

So I have created function which sets username, firstname and lastname of currently logged user, it looks like this:

  profile = {} as Profile;
  
  ...
  
  createProfile() {
    this.afAuth.authState.take(1).subscribe(auth => {
      this.afDatabase.object(`profile/${auth.uid}`).set(this.profile)
        .then(() => this.navCtrl.setRoot(MainPage));
    })
  }

the data on firebase looks like this:

enter image description here

Now, I would like to create new function in a new page called user.ts:

showdata() { }

So it would display username, firstname, and lastname of the user on user.html

the question is how to do this?

1
Im only changing .ts and .html files - Jakub Balicki

1 Answers

1
votes

To retrieve the data, use the below:

 firebase.database().ref().child("profile").on('value', function(snapshot) {
snapshot.forEach(function(child) {
var datas = child.val();
var firstname=child.val().firstname;
var lastname=child.val().lastname;
var username-child.val().username;
  });
});

If you have the userid then you can do child("profile").child(userid).on(..){..} and retrieve without using forEach()

https://firebase.google.com/docs/database/web/read-and-write