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?
ForkJoin method signature has changedThis is now deprecated and you must pass an array of observables to forkJoin operator.
concat() which will handle each observable in sequence.
Overall, in order for forkJoin to emit a value, all given observables have to emit something at least once and complete. If any given observable errors at some point, forkJoin will error as well and immediately unsubscribe from the other observables.
The forkJoin will subscribe to the passed observables, by making the HTTP GET requests. If any input observable errors at some point, forkJoin will find the error as well and all other observables will be immediately unsubscribed.
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
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With