Angular 5 - Rxjs forkJoin

Angular 5 - Rxjs forkJoin

以下代码:

this.playerSearchService.getPlayerByPlayerTag(this.searchValue).flatMap(player =>
  this.clanSearchService.getClanByClanTag(player.clan.tag).map(clan => {
    return Observable.forkJoin([Observable.of(player), Observable.of(clan)])
  })).subscribe(data => {
    this.playerResult = data[0]; <== undefined
    this.clanInfo = data[1];
    console.log(data);
});

尽管控制台向我显示了数据:

ForkJoinObservable {_isScalar: false, sources: Array(2), resultSelector: null}resultSelector: nullsources: Array(2)0: ScalarObservablescheduler: nullvalue: achievements: (32) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]attackWins: 0bestTrophies: 3356bestVersusTrophies: 4711builderHallLevel: 7clan: {tag: "#PRJ9J9GG", name: "Forensik", clanLevel: 14, badgeUrls: {…}}defenseWins: 0donations: 1donationsReceived: 60expLevel: 132heroes: (3) [{…}, {…}, {…}]league: {id: 29000014, name: "Master League II", iconUrls: {…}}legendStatistics: {legendTrophies: 0, previousVersusSeason: {…}, bestVersusSeason: {…}, currentSeason: {…}}name: "Marco"role: "member"spells: (9) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]tag: "#9Y2RJ89YL"townHallLevel: 9troops: (27) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]trophies: 2857versusBattleWinCount: 1027versusBattleWins: 1027versusTrophies: 4000warStars: 665__proto__: Object_isScalar: true__proto__: Observable1: ScalarObservable {_isScalar: true, value: {…}, scheduler: null}length: 2__proto__: Array(0)_isScalar: false__proto__: Observable

data[0]data[1] 未定义我如何从 forkJoin 检索数据?

顺便说一句。 Data.sources[0].values 也不起作用。悬挂时间....

试试这个:

this.playerSearchService.getPlayerByPlayerTag(this.searchValue).switchMap(player =>
Observable.zip(this.clanSearchService.getClanByClanTag(player.clan.tag), Observable.of(player))).subscribe(([tag, player]) => {
        this.playerResult = player;
        this.clanInfo = tag;
    });