I am using Rxjs
in an angualr-cli
application.
in viewer.component.ts
//Other Imports
import { Observable } from 'rxjs/Observable';
//omitting for brevity
export class ViewerComponent implements OnInit, AfterViewInit, OnDestroy {
someFunction(someArg){
//omitting for brevity
let someArray: any = [];
//Add some info
Observable.forkJoin(someArray).subscribe(data => {
//Do something with data
});
}
//omitting for brevity
}
I get and error as
ERROR TypeError: __WEBPACK_IMPORTED_MODULE_2_rxjs_Observable__.Observable.forkJoin is not a function
at ViewerComponent.webpackJsonp../src/app/component/viewer.component.ts.ViewerComponent.someFunction(http://localhost:4200/main.bundle.js:4022:73)
at http://localhost:4200/main.bundle.js:3951:31
But if I Import Rxjs
completely (import 'rxjs';
) everything works. No error.
I cont seem to understand whats additional that needed.
I also tries importing rxjs/Observable/forkjoin
but nothing to avail.
Any pointers on how to go about this.
The RxJS forkJoin() operator is a join operator that accepts an Array of ObservableInput or a dictionary Object of ObservableInput and returns an Observableand then waits for the Observables to complete and then combine last values they emitted.
There are a few steps to accomplish this tutorial:Install Angular CLI and Create Angular 8 Application. Create an Angular 8 Service. Display Multiple Details of Data using Angular 8 Material. Run and Test the Complete Angular 8 RxJS Example.
ForkJoin method signature has changedThis is now deprecated and you must pass an array of observables to forkJoin operator.
As forkJoin only completes when all inner observables complete, we must be mindful if an observable never completes. If this does happen forkJoin will never complete either.
As explained here, you have two options:
In the first case you would use import like this:
import Rx from 'rxjs/Rx';
Rx.Observable.forkJoin(1,2,3)
In the second like this:
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/forkJoin';
I believe what you're looking for is the second option.
For RxJS v6.5+
, it is now:
import { forkJoin } from 'rxjs';
https://www.learnrxjs.io/operators/combination/forkjoin.html
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