AngularFire,如何通过uid在页面上显示姓名/电子邮件

AngularFire, how to show name/email on page through uid?

本文关键字:显示 电子邮件 何通过 uid AngularFire      更新时间:2023-09-26

正如主题所说,如何在页面上打印出来?关于这一点的许多其他主题都在使用 SimpleLogin,它现在已经不推荐使用,所以没有太多使用它,因此另一个线程。

我有一个注册功能(名称+电子邮件+密码

)和一个登录功能(电子邮件+密码),例如,当经过身份验证时,我希望页面打印"Welcome {{user.name}}"。我觉得这是一项非常基本的任务,但我无法完成它。当身份验证并重定向到仪表板时.html(那里的路由存在一些问题,但这是另一篇文章,提示提示) - 它只打印出 uid。

它看起来像这样:

app.controller('dashController', ['currentAuth', '$scope', '$firebaseArray', '$firebaseAuth', '$rootScope', 'Auth', '$location',
  function(currentAuth, $scope, $firebaseArray, $firebaseAuth, $rootScope, Auth, $location){
    var ref = new Firebase('https://url.firebaseio.com');
    $scope.auth = $firebaseAuth(ref);
    $scope.user = $firebaseArray(ref);

    var authData = $scope.auth.$getAuth();
    $scope.id = authData.uid;
}]);

和 html:

<span>Welcome {{id}}</span>

所有 uid 都存储在/users/uid/name+email+pass 中。谢谢!

这没有任何意义:

$scope.user = $firebaseArray(ref);

您的数据库不是数组,因此尝试将其作为数组绑定到范围对任何人都没有帮助。

更有可能是希望将特定用户的配置文件数据绑定到范围:

$scope.user = $firebaseObject(ref.child('users').child(authData.uid));

然后在您看来:

<span>Welcome {{user.name}}</span>

我建议您从头到尾遵循AngularFire编程指南。例如,这样做应该使$firebaseArray()$firebaseObject()之间的区别更加清晰。