我现在可以看到Firebase Firestore的当前用户。但是,当我更新imageURL时,它并不会自动反映在组件中,即使Firebase用户也可以观察到。但是,如果我重新加载页面,它将得到反映。这是我的代码:
auth.service.ts
===============
private user: Observable<User>;
constructor(private afAuth: AngularFireAuth, private afs: AngularFirestore, private afStorage: AngularFireStorage) {
this.user = this.afAuth.authState;
}
get currentuser(): Observable<User> { // This is returning the Firebase current user
return this.user;
}
component.ts
============
async signedUser() {
try {
const demoURL =
'image.appspot.com/o/';
this.sub1 = await this.authService.currentuser.subscribe(user => {
if (user) {
console.log('User exists');
this.imgSource = user.photoURL ? user.photoURL : demoURL;
console.log('imae source========', this.imgSource);
const tempName = user.displayName ? user.displayName.split(' ') : ['user'];
this.user = tempName[0];
}
},
(error) => {
console.log(error);
},
() => {
console.log('------- Observable completed in signed user--------')
})
}
catch (error) {
console.log(error);
console.log(error.code);
}
}
在上面的代码中,当前用户的getter返回一个observable。为什么更改没有自动反映回来?