本文介绍了错误rxjs_Observable __.Observable.forkJoin不是函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在angualr-cli
应用程序中使用Rxjs
.
I am using Rxjs
in an angualr-cli
application.
in viewer.component.ts
in viewer.component.ts
//Other Imports
import { Observable } from 'rxjs/Observable';
//omitting for brevity
export class ViewerComponent implements OnInit, AfterViewInit, OnDestroy {
someFunction(someArg){
//omitting for brevity
let someArray: any = [];
//Add some info
Observable.forkJoin(someArray).subscribe(data => {
//Do something with data
});
}
//omitting for brevity
}
我理解为
ERROR TypeError: __WEBPACK_IMPORTED_MODULE_2_rxjs_Observable__.Observable.forkJoin is not a function
at ViewerComponent.webpackJsonp../src/app/component/viewer.component.ts.ViewerComponent.someFunction(http://localhost:4200/main.bundle.js:4022:73)
at http://localhost:4200/main.bundle.js:3951:31
但是,如果我完全导入Rxjs
(import 'rxjs';
),一切正常.没错我似乎仍了解需要补充的内容.我也尝试导入rxjs/Observable/forkjoin
,但无济于事.
But if I Import Rxjs
completely (import 'rxjs';
) everything works. No error.I cont seem to understand whats additional that needed.I also tries importing rxjs/Observable/forkjoin
but nothing to avail.
有关如何执行此操作的任何指示.
Any pointers on how to go about this.
推荐答案
如此处,您有两种选择:
- 将所有运算符作为一个包导入
- 或单独导入每个运算符
在第一种情况下,您将使用以下导入方式:
In the first case you would use import like this:
import Rx from 'rxjs/Rx';
Rx.Observable.forkJoin(1,2,3)
第二个是这样的
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/forkJoin';
我相信您正在寻找的是第二个选择.
I believe what you're looking for is the second option.
这篇关于错误rxjs_Observable __.Observable.forkJoin不是函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!