所以我开始学习 Angular,我从 2.0 开始,因为它会破坏 1 到那时我正在尝试获取 quick start application从 Angular 网站开始工作
我按照说明设置了代码,并在 IIS 中设置了一个网站以指向源代码目录,但出现错误。
Uncaught (in promise) Error loading "app" at http://localhost:88/app.js
http://localhost:88/app.js:1:46: Unexpected token angular2
有人在 IIS 中设置过这个应用吗?如果可以,你能帮忙吗?
文件 app.js:
import {Component, Template, bootstrap} from angular2/angular2;
//Annotation section
@Component({
selector: 'my-app'
})
@Template({
inline: '<h1>Hello {{name}}</h1>'
})
//Component controller
class MyAppConponent{
constuctor(){
this.name = 'Alice';
}
}
bootstrap(MyAppConponent);
文件index.html
<!-- index.html -->
<html>
<head>
<title>Angular 2 Quickstart</title>
<script src="/quickstart/dist/es6-shim.js"></script>
</head>
<body>
<!-- The app component created in app.es6 -->
<my-app></my-app>
<script>
// Rewrite the paths to load the files
System.paths = {
'angular2/*':'/quickstart/angular2/*.js', // Angular
'rtts_assert/*': '/quickstart/rtts_assert/*.js', // Runtime assertions
'app': 'app.js' // The my-app component
};
// Kick off the application
System.import('app');
</script>
</body>
</html>
此外 - 我确实按照网站指示将应用程序文件命名为 app.es6 但我正在查看扩展名是否有所不同,因为 es6 是新的 javascript 标准并且浏览器可能不支持它然而我得到了
GET http://localhost:88/app.es6 404 (Not Found)
作为该扩展程序的错误。
我的浏览器使用的是 Chrome Canary
最佳答案
看起来像是语法错误
import {Component, Template, bootstrap} from 'angular2/angular2';
应该修复它
关于Angular 2 快速入门应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29191573/