players2:Observable<String[]>;
deletePlayerFromAvailable(id:string, firstName:string, lastName:string): Observable<String[]>{
this.matchDoc = this.afs.doc<Match>(`matches/${id}`);
this.players2 = this.matchDoc.collection<String>('availablePlayers', ref => ref.where('firstname', '==' , firstName)).valueChanges()
return this.players2;
}
我可以使用valueChanges()方法检索数据,但我需要此动态查询的文档ID才能从&lt; availablePlayers&#39;中删除文档。采集。我如何实现这一目标?当我开始使用SnapshotChanges()方法时,错误是
Type 'Observable<DocumentChangeAction[]>' is not assignable to type 'Observable<String[]>'.
on this.players2
如果您需要任何其他详细信息,请与我们联系。
编辑2 检索我需要的doc ID字符串的新方法,但是方法没有返回任何值 - 控制台打印未定义。
getPlayerFromMatchDayAvailable(player:Player, id:String):string{
this.playerscollection = this.afs.collection<Player>(`matchdays/${id}/availablePlayers`, ref => ref.where('email','==','john@test.com'))
this.players2 = this.playerscollection.snapshotChanges()
this.players2.subscribe( data => {
if(data){
console.log(data);
data.map(test => {
console.log(test.payload.doc.id);
this.af = test.payload.doc.id;
});
}
})
console.log(this.af)
return this.af;
// this.players2.forEach(player => {
// player.forEach(playerData => {
// let data = playerData.payload.doc.data();
// let ids = playerData.payload.doc.id;
// this.af = playerData.payload.doc.id;
// console.log(id,data)
// });
// });
}