无法将"Rx"导入我的Angular 2应用程序 [英] Unable to import 'Rx' to my Angular 2 application
问题描述
我在Angular2上还很陌生.我正在尝试使用虚拟应用程序来学习它.
I am pretty new at Angular2. I am trying to learn it using a dummy app.
我最近浏览了有关RxJS的教程,对Observables有了基本了解(或者我至少假设如此).基于此,我有一个想法,可以将正在使用的数组中的用户列表作为流返回.我打算为此使用间隔,并在屏幕上显示一种延迟加载效果.
I have recently gone through a tutorial on RxJS and got a basic hold on Observables (or atleast I assume so). Based on that, I have an idea of returning a list of users from my array in service as a stream. I intent to use interval for it and display a kind of lazy loading effect on screen.
我的意图是:
getUsers() {
return Rx.Observable.from(this.users); //want to add interval too on this
}
但是,我一直坚持将"Rx"导入到我的服务中.在不导入的情况下使用"Rx"显然给我错误.其余的用于Observables和Operator的导入效果很好.
However, I am stuck at importing 'Rx' in to my service. Using 'Rx' without import obviously gives me error. The rest imports for Observables and operator works fine.
我去了node_modules,发现那里也有一个rx
和一个rxjs
模块.但是以某种方式使用以下任何命令,都无法摆脱Rx
上的错误.
I went to node_modules and found there is a rx
and a rxjs
module too. But somehow using any of these below commands, I can't get rid of my error on Rx
.
import 'rxjs/Rx';
import Rx from 'rxjs/Rx';
import { Rx} from 'rx/Rx';
import { Rx} from 'rx';
我在SO上浏览了一些链接,这些链接说Rx
不再与Angular捆绑在一起.但是,我正在使用最新的有角度的官方种子,并且确实看到了rx
和rxjs
软件包.我有package.json
中提到的5.0.1
版本.我在这里假设有什么问题吗?
I went through few links on SO those say Rx
is no longer bundled with Angular. However, I am working with the latest angular official seed and I do see rx
and rxjs
packages. I have a 5.0.1
version mentioned in package.json
. Am I assuming something wrong here ??
请让我知道如何使用Angular 2中的Rx
创建自定义可观测对象.
Please let me know How does one work with creating custom observables using Rx
in Angular 2.
注意:我在使用Http服务进行Observable返回时没有任何问题,只想使用Array从头开始创建Observable
推荐答案
在Angluar 4+中:
In angluar 4+:
import * as Rx from 'rxjs/Rx';
修复此问题后,Rxjs文档仍然是错误的.
Rxjs documentation is still wrong, after fix this.
这篇关于无法将"Rx"导入我的Angular 2应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!