我正在使用 forkJoin 来组合两个 firebase 请求的结果
两个请求都完成并在控制台中记录,但 forkJoin 本身的 map 函数不会触发,因此不会向应用程序返回任何结果
public initGroup(groupname, username){
console.log(groupname, username)//This logs
return Observable.forkJoin([
this.getGroup(groupname, username),
this.groupMembers(username, groupname),
])
.map((data)=>{
console.log(data)//This does not log
this.group = data;
return this.group
})
}
对于各个功能:
public getGroup(groupname, username){
return (this._af.database.object('/groups/'+groupname) as FirebaseObjectObservable<any>)
.map((group)=>{
console.log(group)//This logs
return group
})
}
public groupMembers(username, groupname){
return this.afService.getUserItems(groupname)
.map((users:UserInfo[])=>{
console.log(users)//This logs
return users
})
}
我在组件内订阅:
let conn = this.groupService.initGroup(groupname, username)
.subscribe((data)=>{
console.log(data)//Does not log
......
})