【发布时间】:2016-01-11 17:26:59
【问题描述】:
我正在尝试运行一个基本的 Angular2 应用程序。但是,当我使用live-server 和npm start 运行应用程序时,目前遇到以下错误:
Uncaught ReferenceError: ng is not defined
我安装了最新的 Angular2 npm。这是我的标记:
<html>
<head>
<title></title>
<script src="https://rawgithub.com/systemjs/systemjs/0.19.6/dist/system.js"></script>
<script src="https://code.angularjs.org/tools/typescript.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.0/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.0/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.0/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="app.js"></script>
</head>
<body>
<first-comp></first-comp>
</body>
</html>
我的 app.js 文件:
var FirstComponent = ng.
Component({
selector: 'first-comp'
})
.View({
template: '<h2>I am learning {{ myFramework }}</h2>'
})
.Class({
constructor: function() {
this.myFramework = "Angular2";
}
});
document.addEventListener('DOMContentLoaded', function() {
ng.bootstrap(firstComponent);
});
【问题讨论】:
-
首先你有两次
angular2.dev.js,其次如果你想用ES5编写你应该使用umd包之一。检查这个table。
标签: javascript angular