【发布时间】:2016-03-30 03:15:14
【问题描述】:
我目前正在研究 Angular2,来自 AngularJS 背景。在这件事上,我也在研究 SystemJS 和 Typescript。
但是,我在使用 Typescript 类型和 SystemJS 运行 Angular2 时遇到了问题。使用没有任何类型的 Typescript 可以按预期工作,但是一旦我尝试从 Angular2 类型中加载任何模块,SystemJS 似乎无法解决它。
根据我所读到的,这些类型是随 angular2.dev.js 一起提供的,所以只要我导入它,我应该没问题吗?
该错误与https://github.com/systemjs/systemjs/issues/610 有一些相似之处,但不幸的是他的解决方案对我不起作用。
不幸的是,我对 SystemJS 和 Typescript 的经验是空的,我只是想建立一个系统来学习。所有的库都是最新的,并且刚刚安装了 npm。生成的构建由 NodeJS express 服务器托管,而 Typescript 文件及其类型不是。
我得到的错误是:
GET http://localhost:8000/angular2/angular2 404 (Not Found)
这是我的“index.html”的头部摘录:
<head>
<script src="assets/js/lib/traceur.js"></script>
<script src="assets/js/lib/system.src.js"></script>
<script src="assets/js/lib/Rx.js"></script>
<script src="assets/js/lib/angular2.dev.js"></script>
<script>
System.config({
packages: {
assets: {
format: 'register',
defaultExtension: 'js'
},
}
});
System.import( 'assets/js/boot' )
.then( null, console.error.bind( console ));
</script>
</head>
boot.ts Typescript 文件(我只添加了 bootstrap(),以便 angular2 实际上包含在编译中):
import { bootstrap } from 'angular2/angular2';
bootstrap();
console.log( 'test' );
以及tsc编译后生成的boot.js:
System.register(['angular2/angular2'], function(exports_1) {
var angular2_1;
return {
setters:[
function (angular2_1_1) {
angular2_1 = angular2_1_1;
}],
execute: function() {
angular2_1.bootstrap();
console.log('test');
}
}
});
//# sourceMappingURL=boot.js.map
tsdconfig.json:
{
"compilerOptions": {
"target": "ES5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": true,
"noImplicitAny": false
},
"exclude": [
"node_modules"
]
}
非常感谢您的帮助,祝您假期愉快! :)
【问题讨论】:
-
使用
import {bootstrap} from 'angular2/platform/browser';
标签: node.js angular typescript systemjs