【发布时间】:2018-08-29 11:52:04
【问题描述】:
在初始化我的应用程序时,我调用getProfile () 方法返回用户配置文件信息并显示在屏幕上。
但是每当初始化时,就会出现如下错误:
ERROR TypeError: Can not read property 'uid' of null
auth.service.ts:
authState: any = null;
this.afAuth.authState.subscribe((auth) => {
this.authState = auth;
});
getProfile() {
// error occurs when you try to access this.authState.uid but subscribe
// has not yet completed
return this.afs.collection(`${this.authState.uid}`).doc('perfil-usuario')
.snapshotChanges()
.map(p => {
return { ...p.payload.data() };
});
}
有没有办法在我访问诸如 displayName、photoURL 或 UID 之类的值时输入 authState 而不会出错?
【问题讨论】:
标签: angular typescript firebase firebase-authentication