我试图在用户登录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 };
})
})
}
答案 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(); -这行代码解决了这个问题。