我正在尝试检索Firestore中文档内部的布尔值的实际值。 我有以下代码:
isFollowing: boolean;
following;
ionViewDidLoad(){
const userId = this.navParams.get('userId');
const currentUserId = this.fire.auth.currentUser.uid;
// checks if the currently logged in user is following the user
this.following = this.followSvc.getFollowing(currentUserId, userId)
.valueChanges().subscribe(following => {
this.isFollowing = this.following
})
}
我还有以下提供商选择要阅读的文档:
getFollowing(currentUserId: string, userId: string) {
return this.db.doc(`ProfileUser/${currentUserId}/following/${userId}`)
}
我有一个跟随按钮的ng模板,它被更改为布尔值,如果单击它,它会在firestore中创建一个id + TRUE的布尔键,按钮变为取消关注
toggleFollow() {
const userId = this.navParams.get('userId');
const currentUserId = this.fire.auth.currentUser.uid;
if (this.isFollowing) this.followSvc.unfollow(currentUserId, userId)
else return this.followSvc.follow(currentUserId, userId)
}
字段下方的以及我需要恢复的值
这是用户被关注时出现问题的问题..因为当它还没有被跟踪时它仍然返回TRUE并且按钮获取错误的模板
怎么做?