RxJS 新手,范围不是函数 [英] New to RxJS, range is not a function
问题描述
我正在尝试创建一个简单的 TypeScript 文件来使用 RxJS.这是我所做的:
I'm trying to create a simple TypeScript file to use RxJS. Here is what I did:
npm install rxjs",在我的index.html"中引用了traceur & systemjs"并创建了一个test.ts" 文件:
"npm install rxjs", referenced "traceur & systemjs" in my "index.html" and created a "test.ts" file with this:
import {Observable} from 'rxjs/Rx';
Observable.range(1, 2, 3, 4, 5)
.map(x => x * 2)
.filter(x => x > 5)
.subscribe(
x => console.log(x),
err => console.log('Error'),
ok => console.log('No error')
);
我正在像这样配置 systemjs:
I'm configuring systemjs like this:
System.config({
defaultJSExtensions: true,
map: {
'rxjs': 'node_modules/rxjs'
}
});
System.import('test');
根据文档,Observable"类型应该包含一个范围"方法,但显然它只包含创建"一个......因此,我收到了错误错误:TypeError:Observable_1.Observable.fromArray 不是函数".
According to the documentation, the "Observable" type should contains a "range" method but apparently, it does only contain the "Create" one... Therefore, I got the error "Error: TypeError: Observable_1.Observable.fromArray is not a function".
我对所有这些TypeScript/systemjs/rxjs"都很陌生,所以如果我的问题很愚蠢,我很抱歉:-D
I'm quite new in all this "TypeScript/systemjs/rxjs" stuff so I'm sorry if my question is stupid :-D
推荐答案
你还需要导入范围:
import 'rxjs/add/observable/range';
这篇关于RxJS 新手,范围不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!