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

被刻印的时光 ゝ 提交于 2019-11-29 02:57:06

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.

Did you do this?

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

You have to add methods individually.

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)

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!