且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用户在Angular2的Firebase Auth中登录后执行的操作

更新时间:2023-12-01 16:40:10

也许这是因为你在回调函数中使用这个关键字,它有自己的变量作用域,它没有 af.auth 属性。

Maybe this is because you are using this keyword in callback function which has its own variable scope and it does not have af.auth property.

试试这个。

Try this.

public login() {
    var me = this;
    this.af.auth.login()
      .then(() => {
        console.log("user logged in");
        console.log(me.af.auth);
      });
}



更新



尝试订阅 auth 对象,并且应该通知auth状态更改。

UPDATE

Try to subscribe on auth object and you should be notified on auth state change.

this.af.auth.subscribe(auth => {
  if(auth) {
    console.log('logged in');
  } else {
    console.log('not logged in');
  }
});