我无法获得使用RxJS的最小的Angular 2应用程序。我正在使用Typescript(tsc 1.6.2)和systemjs进行模块加载。我如何让systemjs正确加载Rx模块?我已经用尽了想法尝试,我会很感激任何指向我做错的事情。模块加载对我来说有点神奇。非常令人沮丧。如何使用systemjs在最小的Angular 2应用程序中加载RxJS?
的index.html:
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<script src="../node_modules/es6-shim/es6-shim.js"></script>
<script src="../node_modules/systemjs/dist/system.src.js"></script>
<script src="../node_modules/rx/dist/rx.lite.js"></script>
<script src="../node_modules/angular2/bundles/angular2.dev.js"></script>
</head>
<body>
<app>App loading...</app>
<script>
System.config({
packages: { 'app': { defaultExtension: 'js' } }
});
System.import('app/app');
</script>
</body>
</html>
app.ts:
/// <reference path="../../node_modules/rx/ts/rx.all.d.ts" />
import { bootstrap, Component, View } from 'angular2/angular2';
import * as Rx from 'rx';
@Component({
selector: 'app'
})
@View({
template: `Rx Test`
})
export class App {
subject: Rx.Subject<any> = new Rx.Subject<any>();
}
bootstrap(App);
SystemJS尝试加载不存在的文件:
只要我在上面的代码中注释掉主题,一切都会正常运行,因为不会尝试加载不存在的文件(并且没有加载rx)。
埃里克,感谢您抽出时间回复!这解决了我的一部分神秘。对不起,花了这么长时间回到你身边,我花了大部分时间试图让同一个项目脱机工作(没有任何真正的成功,我必须说)。我使用的VSC和打字稿1.6.2,就是在你的例子中使用的相同transpiler。在“在线”版从** ** app.ts生成的代码有一个稍微不同的头,这似乎使所有的差异(它调用'System.register(...)')。你有过任何成功编译并与VSC/TSC本地运行呢? – Toby
您是否收到任何错误?事实上,在我的离线版本(我自己的项目)中,我有'import *'作为'...'的主题(与我的答案有点不同)。还有其他的东西吗?你的在线和离线版本有什么不同? ? –
所以你在运行时遇到了错误呢?或者它在默默地失败了吗?你是否使用了一些工具,比如JSPM,Webpack或者其他东西?你能创建一个repo,以便我可以克隆它并查看它吗? –