Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度渲染引擎&;Firebase剖面检索_Angularjs_Firebase - Fatal编程技术网

Angularjs 角度渲染引擎&;Firebase剖面检索

Angularjs 角度渲染引擎&;Firebase剖面检索,angularjs,firebase,Angularjs,Firebase,我想要什么: firebase检查页面加载的身份验证 firebase在登录时返回用户ID my函数返回与user.Id关联的用户名 分配给表示用户名的变量 渲染 全页加载 当前行为: 以下配置检索用户名,但仅在我单击已创建的登录按钮后显示用户名。由于某些原因,即使我当前已登录,我也必须单击登录按钮。我想要一个设置,如果我登录了应用程序,从一开始就知道我登录了 crossfitApp.controller('globalIdCtrl', ["$scope",'$q','defautProfi

我想要什么:

  • firebase检查页面加载的身份验证
  • firebase在登录时返回用户ID
  • my函数返回与user.Id关联的用户名
  • 分配给表示用户名的变量
  • 渲染
  • 全页加载
当前行为:

以下配置检索用户名,但仅在我单击已创建的登录按钮后显示用户名。由于某些原因,即使我当前已登录,我也必须单击登录按钮。我想要一个设置,如果我登录了应用程序,从一开始就知道我登录了

crossfitApp.controller('globalIdCtrl', ["$scope",'$q','defautProfileData','$timeout', function ($scope,$q,defautProfileData,$timeout) {

                    var  dataRef =   new Firebase("https://glowing-fire-5401.firebaseIO.com");

        $scope.myFbvar =null;
        $scope.authenticated={
                               currentUser: null,
                               avatarUrl: "", 
                               emailAddress: "",
                                   settings: "",
                                   currentUserid: null,

                            };


        function getProfile(userID,assignMe){

            myprofile= new Firebase("https://glowing-fire-5401.firebaseio.com/profiles/"+userID+"/username");
            myprofile.once('value', function(nameSnapshot) {
                                                            assignMe = nameSnapshot.val();                                                    
                                                        });
            };





                    $scope.auth = new FirebaseSimpleLogin(dataRef, function(error, user) {

                                            if (error) {
                                                                      //Error
                                                    console.log ('error');

                                                } 
                                                else if (user) {
                                                                      //logged in 
                                                    $timeout(function() {

                                                        getProfile(user.id,);

                                                     });
                                                     console.log('logged in');
                                                     $scope.authenticated.currentUserid = user.id ;




                                             }
                                                 else {
                                                     // user is logged out
                                                     console.log('logged out');
                                                     $timeout(function() {
                                                            $scope.authenticated.currentUserid =null;
                                                    });
                                             }


                                      });


    }]);  //Global
else if(user)
逻辑中,您忘记将范围变量放入$timeout内,因此设置正确,但Angular直到下次调用$apply(例如,ng click、ng submit等)时才了解它

因此:


您可以阅读更多有关这一点的信息。

尝试将身份验证放在.run()模块而不是.controller()中,或者放在.service()中,这样您就可以在任何地方使用数据。这也可以解决问题吗?或者这仅仅是为了在任何地方使用吗?看看angularFire()和angularFire seed()。
else if (user) {
   //logged in 
   $timeout(function() {
      getProfile(user.id,);
      $scope.authenticated.currentUserid = user.id ; // moved into $timeout
  });
  console.log('logged in');
}