17
votes

Recently, I decided to migrate a big project that has been created from scratch with the "Quick Start" of Angular to a version using Angular CLI 1.5.5. Right now, I'm fixing the different issues that arise and I can't get to fix this one.

I read that it was better to use lettable operators of rxjs, which I did and it works very well. However, I also have these lines of code:

import { Observable } from "rxjs/Observable";
import "rxjs/add/observable/forkjoin";

...

let piecesGrouping$: Observable<IGroupedPiece[]>[] = deliveries.map(delivery => this._pieceService.getGroupedPieces(delivery.pieces));

Observable
  .forkJoin(...piecesGrouping$)
  .subscribe((groups) => {
    groups.forEach((group, i) => deliveries[i].groupedPieces = group);

    resolve();
  });

They were working very well in the previous version that was using rxjs 5.4.3, now with rxjs 5.5.2, they don't anymore and I get the following error:

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'apply' of undefined TypeError: Cannot read property 'apply' of undefined

I tried to replace the spread operator by piecesGrouping$[0], piecesGrouping$[1] as the error does not say anything about forkJoin in itself, then I get:

ERROR Error: Uncaught (in promise): TypeError: WEBPACK_IMPORTED_MODULE_8_rxjs_Observable.a.forkJoin is not a function TypeError: WEBPACK_IMPORTED_MODULE_8_rxjs_Observable.a.forkJoin is not a function

So it looks like that I'm importing forkJoin the wrong way. I tried to import it from "rxjs/observable/forkJoin" but it didn't work either.

What am I missing?

3

3 Answers

33
votes

Don't use Observable patching, use forkJoin directly:

import {forkJoin} from "rxjs/observable/forkJoin";

forkJoin(...piecesGrouping$).subscribe()

Check this resource to learn more about forkJoin.

6
votes

RxJS 6.x uses this import

import {forkJoin} from 'rxjs';

As stated in the other answers, it still needs to be used as a function as it now stands on its own. Docs are here

5
votes

You should be using it as a function

forkJoin(...piecesGrouping$)
  .subscribe((groups) => {
    groups.forEach((group, i) => deliveries[i].groupedPieces = group);

    resolve();
  });

import statement is changed as

import { forkJoin } from "rxjs/observable/forkJoin";

This was released as a part of 5.2 version . Read the change log