Search code examples
angularangular2-services

property 'forkJoin' does not exist on type 'typeof observable' - angular2


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?


Solution

  • 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.