I was looking to experiment with a forkJoin mainly using the accepted answer here:
Angular2 Observable.forkJoin of observable variables - ReferenceError: Observable is not defined
I'm getting the above error message as forkJoin isn't available.
Anyone know why?
Be aware that if any of the inner observables supplied to forkJoin error you will lose the value of any other observables that would or have already completed if you do not catch the error correctly on the inner observable.
forkJoin is an operator that takes any number of input observables which can be passed either as an array or a dictionary of input observables. If no input observables are provided (e.g. an empty array is passed), then the resulting stream will complete immediately.
forkJoin Improvements This is one of my favorites. The forkJoin observable now takes a dictionary of sources: Moreover, there is one deprecation — forkJoin(a, b, c, d) should no longer be used; Instead, pass an array such as forkJoin([a, b, c, d]) .
Did you do this?
import { Observable } from 'rxjs/Observable'; import 'rxjs/add/observable/forkJoin';
You have to add methods individually.
Angular 6 changes this up a bit. forkJoin has been converted to a regular function so, instead of:
import {Observable} from 'rxjs/Observable'; ... return Observable.forkJoin( this.http.get('someurl'), this.http.get('someotherurl'));
Use:
import {forkJoin} from 'rxjs'; ... return forkJoin( this.http.get('someurl'), this.http.get('someotherurl'));
You can go to https://www.metaltoad.com/blog/angular-6-upgrading-api-calls-rxjs-6 for more explanation.
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