Firebase Firestore get() not working

后端 未结 2 2193
忘了有多久
忘了有多久 2021-02-20 15:40

The part it doesn\'t like is the get() method in ngOnInit(). Is says, \"[ts] Property \'get\' does not exist on type \'AngularFirestoreDocument<{}>\'.\"

2条回答
  •  囚心锁ツ
    2021-02-20 16:33

    Actually, AngularFirestoreDocument<{}> doesn't have get property, use AngularFirestoreDocument<{}>.ref instead:

    this.afs.collection("users")
                .doc(this.id)
                .ref
                .get().then(function(doc) {
                    if (doc.exists) {
                        console.log("Document data:", doc.data());
                    } else {
                        console.log("No such document!");
                    }
                }).catch(function(error) {
                    console.log("Error getting document:", error);
                });
    

提交回复
热议问题