问题
I'm trying to create a simple TypeScript file to use RxJS. Here is what I did:
"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')
);
I'm configuring systemjs like this:
System.config({
defaultJSExtensions: true,
map: {
'rxjs': 'node_modules/rxjs'
}
});
System.import('test');
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".
I'm quite new in all this "TypeScript/systemjs/rxjs" stuff so I'm sorry if my question is stupid :-D
回答1:
You need to also import range:
import 'rxjs/add/observable/range';
回答2:
For rxjs 6.*
import { range } from "rxjs";
const observable = range(0, 4);
来源:https://stackoverflow.com/questions/36167740/new-to-rxjs-range-is-not-a-function