如果调用property,则Subscribed元素为null

时间:2017-03-23 10:47:37

标签: javascript angular firebase firebase-authentication angularfire2

使用angularfire2订阅auth对象。运行此代码工作正常,authData对象将打印到控制台:

this.af.auth.subscribe(authData => {
  console.log(authData);
});

输出:Object {auth: X, uid: "xXj8n6KnZcNDU8rBH....", provider: 3, google: Gi}

但是当我想只打印其中一个属性时,它会说该对象为null:

this.af.auth.subscribe(authData => {
  console.log(authData);
  console.log(authData.uid);
});

错误:Cannot read property 'uid' of null

如何访问authData的属性?

0 个答案:

没有答案