Ionic 3 + Firestore从布尔字段中恢复值

时间:2017-10-14 00:17:33

标签: angular typescript firebase ionic3 google-cloud-firestore

我正在尝试检索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)

}

字段下方的

以及我需要恢复的值

enter image description here

这是用户被关注时出现问题的问题..因为当它还没有被跟踪时它仍然返回TRUE并且按钮获取错误的模板

enter image description here enter image description here

怎么做?

0 个答案:

没有答案