该代码应该显示一个包含Hello World的div,但是我收到错误信息Uncaught TypeError:System.import不是一个函数.我正在关注ng-book2入门教程视频,该视频在index.html中包含以下代码:
<!DOCTYPE html>
<html>
<head>
<title>Angular 2</title>
<script src="js/traceur-runtime-0.0.90.js"></script>
<script src="js/system-0.18.4.js"></script>
<script src="js/angular2-alpha31.js"></script>
</head>
<body>
<script>System.import('js/app');</script>
<hello-world></hello-world>
</body>
</html>
和app.ts:
/// <reference path="../lib/node_modules/angular2/angular2.d.ts" />
import {
Component,
View,
bootstrap
} from 'angular2/angular2';
// Annotation section
@Component({
selector: 'hello-world'
})
@View({
template: '<div>Hello World</div>'
})
// Component controller
class HelloWorld {
}
bootstrap(HelloWorld);
最后是当前目录结构:
/ng2
/js
angular2-alpha31.js
app.js
app.js.map
system-0.18.4.js
system-0.18.4.js.map
traceur-runtime-0.0.90.js
index.html
到处寻找解决方案,only issue that seems similar enough指出系统的config.js存在问题.除了本教程之外,该视频还显示了该配置的工作原理.我应该提到,这是托管在远程服务器上,而不是视频中使用的本地HTTP服务器.
开发人员窗口的屏幕截图:
上面的目录结构中显示的每个文件是GitHub上最新的文件.如果我使用的是远程服务器,或者我完全丢失了其他东西,是否应该包含默认配置文件?
解决方法:
在进一步处理这些文件之后,我发现Angular2正在使用其自己的方法覆盖SystemJS的System对象.如果angular2.js在HTML中移到了system.js之上,则该语句
<script>System.import('js/app');</script>
使用正确的System对象.
这不应该发生,但是暂时是一个问题.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。