我正在尝试从一组团队中返回选定的团队。看来我需要将快照转换为团队对象。我怎么做?有没有更简单的方法将快照转换为数组?我是 firebase/Angular 的新手,所以希望我错过了一些简单的东西。
使用角度 5.5.2
export class Team {
internalTeamName: string;
externalTeamName: string;
creatorNumber: number;
teamAdmins: TeamMember[];
teamMembers: TeamMember[];
constructor(code ommitted)
}
Run Code Online (Sandbox Code Playgroud)
服务模块
loadTeams(email){
const teamArray: Team[] = null;
this.firestore.collection('teams', ref => ref.where('teamAdmins', 'array-contains', email))
.get()
.forEach(function(childSnapshot) {
teamArray.push(childSnapshot);})
.then(
return teamArray )
.catch(
err => console.log(err)
)
Run Code Online (Sandbox Code Playgroud)
上述代码的错误:“QuerySnapshot”类型的参数不能分配给“Team”类型的参数。类型“QuerySnapshot”缺少“团队”类型中的以下属性:internalTeamName、externalTeamName、creatorNumber、teamAdmins、teamMembers
函数调用上述函数:调用服务函数时的最佳实践是什么?
public teamArray: Team[] = null;
ngOnInit() {
this.teamArray = this.teamCrudService.loadTeams(this.authService.email);
}
Run Code Online (Sandbox Code Playgroud)