2
votes

After upgrading to angular 4.0 i am getting errors for RxJs variables. Everything builds fine. But when i load the page i get this error

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'forkJoin' of undefined TypeError: Cannot read property 'forkJoin' of undefined

i am using forkJoin in an init function

init(){
  return Observable.forKJoin()
}

I import the Observable at the top and it looks like this

import {Observable,Observer,Subject,BehaviorSubject} from 'rxjs/Rx';

what changes were made that would all of a sudden cause these issues. My code runs fine pre 4.0

1
import the forkJoin operator from 'rxjs' - Seiyria
Are you really importing from 'rxjs/Rx'? That file includes all of the side-effect imports for the operators so you should not have the problem you've described. - cartant

1 Answers

0
votes

rxjs has a bit of a "choose what you want to import" approach to Observables. Basically it's a Decorator pattern where you import the base Observable and then you import all the fancy things you want it to do. In addition to importing the observable, you also need to import:

import 'rxjs/add/observable/forkJoin';

I usually have an rxjs-operators.ts file that I just import anytime I need anything from it.

Older versions of rxjs didn't work like this. I believe it was sometime during v2's RC period rxjs switched to this model.

All of these extra imports are part of the rxjs package so you won't need to download anything new or add anything to your package.json to access them.