我試圖在Firebase中創建一個連接。Flatten Observable <Observable <Object[]>>
因此,我異步地從數據庫中獲取ID數組,然後爲每個ID然後異步加載實際的對象。並且該函數應該返回Observable
因此,通過第一個異步請求,我得到了Observable(字符串就是id)。 所以,無論我在這裏嘗試,我要麼Observable或其他一些不是我想要得到的東西。
的代碼:
getUserFavourites(userId = ""):Observable<any[]> {
return this.af.database.list('/ranks_by_user/likes/'+userId, {
query: {
orderByKey: true,
limitToFirst: 50
}
}).flatMap((likes:any[]) => {
return like.map(like => {
return this.af.database.object("/citations/" + like.$key)
});
});
}
和錯誤是:
Type 'Observable<FirebaseObjectObservable<any>>' is not assignable to type 'Observable<any[]>'.
您可以在問題中包含代碼嗎? – cartant
用代碼 –
更新您需要包含'Citation'的代碼。是一個接口還是一個類?如果它是一個類,至少你需要指出構造函數需要的參數。 – cartant