Firebase Firestore get() not working

后端 未结 2 2141
忘了有多久
忘了有多久 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:31

    You're using Angular Fire, so the syntax is the following:

    this.afs.collection("users").doc(this.id).valueChanges(user => {
         console.log(user);
    });
    

    Read the documentation here: https://github.com/angular/angularfire2

    0 讨论(0)
  • 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);
                });
    
    0 讨论(0)
提交回复
热议问题