包括连接的 Typescript JS outFile - Angular 2 + Typescript

kar*_*rns 4 typescript systemjs angular

我有以下代码:

索引.html

<script src="node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>   
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/router.dev.js"></script>
<script src="node_modules/angular2/bundles/http.dev.js"></script>

<script src="test.js"></script

<script>

  System.import('test.js')
        .then(null, console.error.bind(console));
</script>
Run Code Online (Sandbox Code Playgroud)

配置文件

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "outFile": "test.js"
  },
  "exclude": [
    "node_modules",
    "typings/main",
    "typings/main.d.ts"
  ]
}
Run Code Online (Sandbox Code Playgroud)

在我的项目的根目录中,我将 tsc 创建的“outFile”命名为“test.js”——似乎所有组件、模块等都在 test.js 中正确连接,但应用程序没有加载任何内容除了最初的“正在加载...”之外,在浏览器中访问 index.html 时没有控制台错误。

还要注意初始 index.html:

<body>
  <rz-app>Loading...</rz-app>
</body>
Run Code Online (Sandbox Code Playgroud)

所以我实际上只是在 html 页面上得到“正在加载...”。

我一直在用头撞墙,我知道这很简单......

那么,我做错了什么 - 如何在我的 html 中包含连接的 ts outFile?

小智 5

不确定这是否已经解决,但我遇到了同样的问题并发现它修复了它:

查看您的test.js文件(通过 tsc->outFile 输出的文件)并查找您的应用程序(看起来像rzApp)。应该有一些代码看起来像System.register("app", ["angular2/platform/browser", ...名称(在本例中app)是您要在System.import()呼叫中使用的名称。所以在我的情况下,我使用了System.import('app').then(null, console.error.bind(console));一切都开始工作。确保你有你test.js<script>标签。

我认为这与第一个答案中描述的内容相似,但我不清楚,所以我想我会以一种帮助我意识到发生了什么的方式重新措辞。