【问题标题】:FirebaseUI authState subscribe: returning valuesFirebaseUI authState subscribe:返回值
【发布时间】:2018-04-16 05:07:05
【问题描述】:

我在理解如何返回和使用通过 angular 和 FirebasUI (https://www.npmjs.com/package/firebaseui-angular) 返回的数据时遇到了一些麻烦。

现在,我正在使用 authstate 返回数据

ngOnInit(): void {
this.afAuth.authState.subscribe(d => console.log(d));
}

这会在控制台中返回

{currentUser: Hk, credential: null, redirectUrl: undefined}

我的问题:如何访问 currentUser 以使用 *ngIf 应用我的页面的条件格式。

提前致谢

【问题讨论】:

    标签: angular firebase angularfire2 firebaseui


    【解决方案1】:

    好的,我找到了一种方法来执行请求的操作:

    首先在组件类中声明一个属性:

    email: string = 'placeHolder';
    

    然后在订阅响应中,我从d 分配所需的数据:

    ngOnInit(): void {
    this.afAuth.authState.subscribe(d =>
      {
        console.log(d);
        this.email = d.email;
        if (this.email != 'placeHolder') {
          this.hasEmail = true;
        } else {
          this.hasEmail = false;
        }
      });
    

    }

    之后,我只需在我的选择器中使用*ngIf="hasEmail",它就可以工作了!

    也许有更好的解决方案,但至少这对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-31
      • 1970-01-01
      • 1970-01-01
      • 2022-01-05
      • 2020-12-21
      • 1970-01-01
      • 2020-02-14
      • 2018-05-24
      相关资源
      最近更新 更多