Angularfire2 firestore快照更改更改为不检索数据,除非登录后重新加载应用程序

时间:2019-06-10 03:22:28

标签: ionic3 angularfire2

我试图在用户登录Ionic 3 App后从Firestore检索数据。 snapshotChanges在首次登录时返回null。但是,一旦我重新启动应用程序,它就会检索数据。可能是什么问题?

getMsg(chatRoomName, privateGroupChatroomName, sortBy, count = 10) {
    this.todosCollection = this.afs.collection('chat').doc(chatRoomName)
        .collection<chatMsg>(privateGroupChatroomName, ref => ref.orderBy(sortBy, 'desc').limit(count))
    return this.chatCollection.snapshotChanges().pipe(map(msg => {
        return msg.map(col => {
            const data = col.payload.doc.data();
            const id = col.payload.doc.id;
            const doc = col.payload.doc;
            return { id, ...data, doc };
        })
    })
}

1 个答案:

答案 0 :(得分:0)

this.afAuth.auth.signInWithEmailAndPassword(Globals.userDetails.email, 'KafeTEENgoogleFirebasePwd').then(cred => {
              this.angularFireStore.firestore.enableNetwork();
              console.log('Firebase log in');
            }

this.angularFireStore.firestore.enableNetwork(); -这行代码解决了这个问题。

相关问题