包括串联的打字稿JS outFile-Angular 2 +打字稿 [英] Including Concatenated Typescript JS outFile - Angular 2 + Typescript

查看:77
本文介绍了包括串联的打字稿JS outFile-Angular 2 +打字稿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

index.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>

tsconfig.json

{
  "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"
  ]
}

在我项目的根目录中,我创建了由tsc创建的"outFile",名为"test.js"-似乎所有组件,模块等都正确地串联在test.js中,但该应用程序没有除了最初的正在加载..."以外,什么都不会加载,并且在浏览器中访问index.html时没有控制台错误.'

And in the root of my project I have the "outFile" created by tsc named as "test.js" - it appears that all of the components, modules, etc are concatenated in test.js correctly but the app doesn't load anything other than the initial "loading..." and there are no console errors when visiting index.html in the browser.'

还要注意,初始index.html:

Also note that the initial index.html:

<body>
  <rz-app>Loading...</rz-app>
</body>

所以我实际上只是在html页面上正在加载...".

So I actually just get "loading..." on the html page.

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

I've been beating my head against a wall and I know it is something simple...

Q 那么,我在做什么错-如何在我的html中包含串联的ts outFile?

Q So, what am I doing wrong - how do I include the concatenated ts outFile in my html?

推荐答案

不确定是否已解决此问题,但我遇到了同样的问题,并已解决此问题:

Not sure if this has been figured out yet, but I was running into the same issue and found this fixed it:

查看您的test.js文件(通过tsc-> outFile输出的文件)并查找您的应用程序(看起来像rzApp之类的东西).应该有一些看起来像System.register("app", ["angular2/platform/browser", ...的代码.名称(在本例中为app)是您要在System.import()调用中使用的名称.因此,以我为例,我使用了System.import('app').then(null, console.error.bind(console));,一切开始正常工作.确保在<script>标记中包含test.js.

Look at your test.js file (the one that was outputted via tsc->outFile) and look for your app (looks like it's something like rzApp). There should be some code that looks something like System.register("app", ["angular2/platform/browser", ... The name (in this case app) is what you want to use in your System.import() call. So in my case, I used System.import('app').then(null, console.error.bind(console)); and everything started working. Make sure you have your test.js in <script> tags.

我认为这与第一个答案中描述的内容类似,但是我不清楚,因此我认为我将以一种有助于我意识到正在发生什么的方式对其重新措词.

I think this is similar to what was being described in the first answer, but it was unclear to me so I figured I'd re-word it in a way that helped me realize what was going on.

这篇关于包括串联的打字稿JS outFile-Angular 2 +打字稿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆