Javascript angularjs登录的用户信息将在整个应用程序中可用

Javascript angularjs登录的用户信息将在整个应用程序中可用,javascript,angularjs,angularjs-scope,firebase-realtime-database,firebase-authentication,Javascript,Angularjs,Angularjs Scope,Firebase Realtime Database,Firebase Authentication,我想让用户信息在登录后对所有视图都可用。如何修改代码以从另一个视图访问笔名? 你能举个例子吗? 这是我的登录控制器: app.controller("MyregisterCtrl", ["$scope", "$stateParams", "Auth", "$state", "$location", "$modal", "DatabaseRef", function ($scope, $stateParams, Auth, $state, $location, $modal, Databa

我想让用户信息在登录后对所有视图都可用。如何修改代码以从另一个视图访问
笔名

你能举个例子吗?

这是我的登录控制器:

app.controller("MyregisterCtrl", ["$scope", "$stateParams", "Auth", "$state", "$location", "$modal", "DatabaseRef",
    function ($scope, $stateParams, Auth, $state, $location, $modal, DatabaseRef) {
        $scope.user = {};

        $scope.signIn = function () {
            if (!$scope.user.email && !$scope.user.password) {
                toastr.error("Add email and password");
            } else {
                Auth.$signInWithEmailAndPassword($scope.user.email, $scope.user.password)
                    .then(function(firebaseUser) {
                        //=====user info=================
                        var userId = firebase.auth().currentUser.uid;
                        DatabaseRef.ref('/users/' + userId).once('value')
                            .then(function(snapshot) {
                                pseudonym = snapshot.val().pseudonym;
                                console.log("pseudonym: ", pseudonym);
                                return pseudonym;

                            });
                        //======================
                        $state.go('app.dashboard');

                        if (!firebaseUser.emailVerified) {
                            toastr.info('Your email is NOT verified.', 'Verify email!');
                            $state.go('login.signin');
                        }
                    })
                    .catch(function(error) {
                        toastr.error(error.message, error.reason, { timeOut: 10000 });
                        $scope.user = {};
                    })
            }
        };
}]);

console.log(“笔名:”,笔名)提供了我想要访问的内容,但无法从其他视图访问它,例如,只需键入{pseuronym}}。

分配给$scope变量,只要您想在视图上显示

pseudonym = snapshot.val().pseudonym;
$scope.pseudonym =pseudonym;