I'm using SystemJS to load my es2015 project into the browser.
This is what I did
import {Observable} from 'rxjs/Rx';
const button = document.querySelector('button');
const start$ = Observable.fromEvent(button, 'click');
In this case Observable
is undefined
. So I tried
import Observable from 'rxjs/Observable';
In which case Observable
is an object but Observable.fromEvent
is undefined
(it seems to be an empty object)
Finally I did
import Rx from 'rxjs/Rx' // Rx.Observable
which did work. Any ideas why the other two didn't work? I have seen code in which they used these. What would be the preferred way to import Observable
?
UPDATE: As stated below its all described in the README. However if I do that
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/fromEvent';
const start$ = Observable.fromEvent(startButton, 'click');
I get Observable
is undefined
. And if I do
import Observable from 'rxjs/Observable';
the Observable
is an empty object again. The fromEvent
is not added.
I'm using RxJs 5.1.1 and here is my index.html/systemjs part:
<script src="./node_modules/systemjs/dist/system.js"></script>
<script>
SystemJS.config({
baseURL: 'node_modules',
packages: {
'.': {
defaultJSExtensions: 'js'
}
},
map: {
'plugin-babel': 'systemjs-plugin-babel/plugin-babel.js',
'systemjs-babel-build': 'systemjs-plugin-babel/systemjs-babel-browser.js'
},
transpiler: 'plugin-babel'
});
SystemJS.import('/js/main.js');
</script>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…