使用@ angular / fire将文档添加到Firestore集合将返回Promise。我想做的是添加文档,但是返回创建的文档的Observable。这是到目前为止我尝试过的内容:
colRef: AngularFirestoreCollection = this.afs.collection<Session>('sessions');
add(session: Session): Observable<Session> {
return this.colRef.add(session).then((docRef) {
return this.colRef.doc<Session>(docRef.id).valueChanges();
})
}
当然,这是行不通的,它正在尝试返回Promise<Observable<Session>>
。我知道为什么不起作用,但不知道如何实现我的目标。任何帮助,不胜感激!