forkjoin returns 没有结果

forkjoin returns no results

我正在使用 forkJoin 合并两个 firebase 请求的结果

两个请求都完成并记录在控制台中,但是 forkJoin 本身的映射函数没有触发,因此没有结果返回给应用程序

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
                  ......
                })

事实证明,forkJoin 不适用于 firebase observables,

当我更新到

public initGroup(groupname, username){
  return Observable.combineLatest([
      this.getGroup(groupname, username),
      this.groupMembers(username, groupname)

  ])
    .map((data)=>{
      console.log(data)//This now logs
      this.group = data;
      return this.group
    })


}

combineLatest 使其按预期工作

这是我使用 Firestore 的用例。

 import { Observable } from 'rxjs/Observable';
 import { combineLatest } from 'rxjs/observable/combineLatest';

 constructor((){}

getAllBudgetGroups() {
    const loading = this.loadingProvider.presentLoader();
    try {
     this.budgetGroups$ = this.budgetGroupProvider.getAllTempBudgetGroups().valueChanges();
     this.defaultBudgetGroups$ = this.budgetGroupProvider.getDefaultBudgetGroups().valueChanges();
     combineLatest(this.budgetGroups$, this.defaultBudgetGroups$).subscribe(([res1, res2]) => {
        this.budgetGroupSortedList = concat(res1, res2);
        this.loadingProvider.dismissLoader(loading);
     }, err => {
        console.log(err);
        this.loadingProvider.dismissLoader(loading);
      });
    }
    catch (err) {
      console.log(err);
      this.loadingProvider.dismissLoader(loading);
    }
  }