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

6

42

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?

Kappenne answered 18/7, 2016 at 18:36 Comment(0)
D
58

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.

Decadence answered 27/8, 2018 at 19:25 Comment(0)
P
49

Did you do this?

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/forkJoin';

You have to add methods individually.

Palish answered 8/9, 2016 at 15:39 Comment(1)
Note that this is a static method, so as Dan wrote, you have to import 'rxjs/add/observable/forkJoin', and not import 'rxjs/add/operator/forkJoin'. Have been bitten by that twice...Revest
B
13

You just need to replace

import { Observable } from 'rxjs/Observable';

by

import { Observable } from 'rxjs/Rx';

and it will start working

Warning: Do not use this method as it will include the entire RxJs library (increasing kb bundle size)

Buddleia answered 5/12, 2016 at 6:8 Comment(4)
@dan-cancro 's solution is better if you do not want to download the entire library.Penicillium
Really, really don't import all of "rxjs/Rx", it's huge and most projects won't use more than a very small number of its exports.Tham
this solution worked fine with Angular 4 for me, but I'm having issues with Angular 5 (in production build)Miscarry
Warning: Do not use this method as it will include the entire RxJs library (increasing kb bundle size)Zosi
E
3

Check your version of Rxjs, if you are using Rxjs 6, use import { Observable } from 'rxjs/Observable'; import 'rxjs/add/observable/forkJoin'; won't work, use import { Observable, forkJoin } from 'rxjs' instead

Extraversion answered 24/7, 2018 at 17:45 Comment(0)
P
1

I have been running Angular version 5.2.0 and faced similar problem. So instead of calling observable with the following way

import { Observable } from 'rxjs/observable'

I imported Observable by including the entire RxJs library

import { Observable } from 'rxjs/Rx'

Then for the forkJoin, included the below import module

import 'rxjs/add/observable/forkJoin';

and code compiled successfully.

Pinchhit answered 16/6, 2018 at 9:52 Comment(0)
G
1

For me, Angular 4 it helps:

import {Observable} from 'rxjs/Rx';
instead of:
import {Observable} from 'rxjs/Observable';
Goggleeyed answered 3/11, 2019 at 10:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.