7

此代码应该显示div包含 Hello World,但我收到错误Uncaught TypeError: System.import is not a function。我正在关注 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

环顾四周寻找解决方案,唯一看起来足够相似的问题是 System 的config.js. 除本教程外,视频显示此工作没有任何配置提示。我应该提到,这是托管在远程服务器上,而不是视频中使用的本地 HTTP 服务器。

开发者窗口截图:

System.import 不是函数

文件列表

上述目录结构中显示的每个文件都是截至撰写本文时 GitHub 上最新可用的文件。如果我使用远程服务器或者我完全遗漏了其他东西,我应该包括一个默认配置文件吗?

4

2 回答 2

6

在进一步玩弄这些文件之后,我发现 Angular2 正在System用它自己的对象覆盖 SystemJS 的对象。如果在 HTML 中angular2.js移到上面system.js,则语句

<script>System.import('js/app');</script>

使用正确的 System object。

这不应该发生,但它暂时是一个问题。

于 2015-07-28T16:47:38.027 回答
1

未捕获的类型错误:System.import 不是函数

js/system-0.18.4.js无法加载的故事指示。

于 2015-07-16T23:46:18.537 回答