Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 205
thegunner Avatar asked Jul 18 '16 18:07

thegunner


People also ask

What happens if observable fails in forkJoin?

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.

What is observable forkJoin?

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.

Is forkJoin deprecated?

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]) .


2 Answers

Did you do this?

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

You have to add methods individually.

like image 77
Dan Cancro Avatar answered Sep 22 '22 14:09

Dan Cancro


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.

like image 29
Narsters Avatar answered Sep 26 '22 14:09

Narsters