【问题标题】:Getting user data from firebase (ionic)从 firebase (ionic) 获取用户数据
【发布时间】:2018-03-29 13:53:55
【问题描述】:

所以我创建了设置当前登录用户的用户名、名字和姓氏的函数,如下所示:

  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));
    })
  }

firebase 上的数据如下所示:

现在,我想在一个名为 user.ts 的新页面中创建新函数:

showdata() { }

因此它将在 user.html 上显示用户的用户名、名字和姓氏

问题是如何做到这一点?

【问题讨论】:

  • 我只更改 .ts 和 .html 文件

标签: firebase ionic-framework firebase-realtime-database ionic3


【解决方案1】:

要检索数据,请使用以下命令:

 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;
  });
});

如果您有用户 ID,那么您可以使用 child("profile").child(userid).on(..){..} 并在不使用 forEach() 的情况下进行检索

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

【讨论】:

    猜你喜欢
    • 2019-10-22
    • 2020-03-19
    • 1970-01-01
    • 2020-11-05
    • 1970-01-01
    • 1970-01-01
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多