Firebase个人资料集成 [英] Firebase profile integrations

查看:100
本文介绍了Firebase个人资料集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里试图做的是在启动时实现一个功能。我想要我的用户的Firebase身份验证电子邮件变量设置一个变量,表示当前用户登录到我的应用程序?

使用以下代码,设置用户变量的行在单击登录之后起作用,但在页面加载之后不起作用!控制台日志工作完美启动,但不是用户设置为电子邮件...
$ b $ pre $ crossfitApp.controller(' globalIdCtrl',[$ scope,'defautProfileData',
function($ scope,defautProfileData){

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

$ scope.authenticated = {
currentUser:10007,
emailAddress:,
设置:,

};

$ scope.auth = new FirebaseSimpleLogin(dataRef,function(error,user){
if(error){
//尝试登录时发生错误
console.log(error);
} else if(user){
//不工作
$ scope.authenticated .currentUser = user.id;
$ b console.log('User ID:'+ user.id +',ProvideFr:'+ user.provider + user);
console.log用户);
} else {
conso le.log($ scope.auth);
alert('deuces');
//!触发器未登录
}
});

}
]); // GlobaldCtrl


解决方案

不会调用FirebaseSimpleLogin Angular的 HTML编译器的范围。通常情况下,无论何时调用ng-click,ng-submit等,Angular都会触发$ scope。$ apply(),它检查对绑定的JavaScript变量所做的任何更改,并将其应用于DOM元素。



当Angular以外的事件更改变量时,您需要通过手动触发$ apply事件来让Angular知道。最安全的方法是使用$ timeout:

$ $ $ $ $ $ $ $ $ $ $> angular.controller('MyCtrl',function($ scope,$超时){
$ scope.auth = new FirebaseSimpleLogin(dataRef,function(error,user){
if(error){
//尝试登录时发生错误
console .log(error);
} else if(user){
$ timeout(function(){
$ scope.currentUser = user.uid;
});
$ b} console.log('not logged in');
}
});

通常,user.uid更喜欢user.id,因为它是唯一的提供者。



类似于 AngularFire 可以为您节省很多麻烦,因为它可以抽象出很多集成Firebase和Angular的复杂性。 p>

What I am trying to do here is to implement a functionality on the start-up. I want my user's firebase authentication email variable to set a variable that represents the current user logged into my app?

With the following code the line that sets the user variable works after I click log in but not on page load! The console logs work perfectly on start-up but not the setting of user to the email...

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

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

    $scope.authenticated = {
      currentUser: 10007,
      emailAddress: "",
      settings: "",

    };

    $scope.auth = new FirebaseSimpleLogin(dataRef, function (error, user) {
      if (error) {
        // an error occurred while attempting login
        console.log(error);
      } else if (user) {
        //Not working
        $scope.authenticated.currentUser = user.id;

        console.log('User ID: ' + user.id + ', ProvideFr: ' + user.provider + user);
        console.log(user);
      } else {
        console.log($scope.auth);
        alert('deuces');
        //!Trigger not logged in
      }
    });

  }
]); //GlobaldCtrl

解决方案

The callback to FirebaseSimpleLogin is not invoked inside the scope of Angular's HTML compiler. Normally, whenever you invoke ng-click, ng-submit, et al, Angular fires $scope.$apply(), which checks for any changes to the bound JavaScript variables and applies those to the DOM elements.

When an event outside of Angular changes a variable, you need to let Angular know by manually triggering a $apply event. The safest way to accomplish this is to use $timeout:

angular.controller('MyCtrl', function($scope, $timeout) {
   $scope.auth = new FirebaseSimpleLogin(dataRef, function (error, user) {
     if (error) {
       // an error occurred while attempting login
       console.log(error);
     } else if (user) {
       $timeout(function() {
          $scope.currentUser = user.uid;
       });
    } else {
       console.log('not logged in');
    }
});

In general, prefer user.uid to user.id, as it is unique across providers.

A library like AngularFire can save you a lot of trouble, as it abstracts a lot of the complexities of integrating Firebase and Angular.

这篇关于Firebase个人资料集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆