我已升级到Angular2@2.0.0-beta.0。 app.ts和boot.ts都在我的src目录中(与Quickstart中的app相比)。 src和index.html位于项目目录中 - angular2-oPost,与Quickstart示例类似。我已经尝试了很多东西但总是得到 - 找不到boot.js,错误加载boot.js我的index.html加载脚本全部加载并且是:
<base href="/src"/>
<!--1. Load library links for ES6-related imports, then load angular2 modules -->
<script src="./angular2-oPost/node_modules/systemjs/dist/system.src.js"></script>
<script src="./angular2-oPost/node_modules/angular2/bundles/angular2-polyfills.min.js"></script>
<script src="./angular2-oPost/node_modules/rxjs/bundles/Rx.js"></script>
<script src="./angular2-oPost/node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="./angular2-oPost/node_modules/angular2/bundles/router.min.js"></script>
<!-- 2. Configure SystemJS -->
<script>System.config({
packages: {
src: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('src/boot').then(null, console.error.bind(console));
</script>
boot.ts来自Quickstart,只是:
"use strict";
import { bootstrap } from 'angular2/platform/browser';
import { ResidenceApp } from './app';
bootstrap( ResidenceApp );
app.ts包含一些导入语句,@ Component,@ View,@ RouteConfig和一个bootstrap语句。没有加载。 Console错误声明是:
GET http://localhost/src/boot.js [HTTP/1.1 404 Not Found 31ms]
15:53:05.058 Error: Unable to load script http://localhost/src/boot.js
Error loading http://localhost/src/boot.js
Stack trace: error@http://localhost/angular2-oPost/node_modules/systemjs/dist/system.src.js:2506:18
[2]</</r.prototype.run@http://localhost/angular2-oPost/node_modules/angular2/bundles/angular2-polyfills.min.js:1:1994
[2]</</r.prototype.bind/<@http://localhost/angular2-oPost/node_modules/angular2/bundles/angular2-polyfills.min.js:1:1718
我正在使用systemjs版本0.19.9如果我将System.import语句更改为
System.import('src/boot.js')
然后找到并加载启动,但app.js成为新问题,依此类推其他组件,如果它(或它们)是硬编码的。
需要改变什么?
答案 0 :(得分:5)
尝试以下加载和配置库的顺序,
<!-- ES6-related imports -->
<script src="/node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="/node_modules/es6-shim/es6-shim.min.js"></script>
<script src="/node_modules/systemjs/dist/system.js"></script>
<script>
//configure system loader
System.config({defaultJSExtensions: true});
</script>
<script src="/node_modules/rxjs/bundles/Rx.js"></script>
<script src="/node_modules/angular2/bundles/angular2.min.js"></script>
<script>
//bootstrap the Angular2 application
System.import('dist/hello').catch(console.log.bind(console));
</script>
参考:https://github.com/pkozlowski-opensource/ng2-play/blob/master/index.html
答案 1 :(得分:0)
与QuickStart不完全相同的SystemJS配置。你试过了吗?
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
答案 2 :(得分:0)
我在main上有同样的问题。将导入更改为
import {AppComponent} from './app.component';
那应该解决它
答案 3 :(得分:0)
同样的错误恰好发生在我身上。如果上面的加载和配置库序列不适合您,请尝试此操作。
它可能起作用的原因是您可能会更改根名称和最后一次运行&#34; npm install&#34;在构建node_modules时包含了绝对Web路径。
另外,还要注意index.html中定义的包。如果您更改包含该应用程序的任何文件夹名称,例如,如果您更改了&#34; app&#34;对于&#34; modules&#34;,您需要在&#34;包中更改它:&#34 ;.
就我而言,我将引导放在WebContent / boot文件夹下,其中WebContent是web根目录,所以这里是index.html中System.config的脚本:
<script>
System.config({
packages: {
modules: {
format: 'register',
defaultExtension: 'js'
},
boot: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('./boot/boot')
.then(null, console.error.bind(console));
</script>