期待已久的Angular 2
Angular 2是一个使用HTML与javascript构件SPA web应用程序的框架,历经了一年多的developer preview以及alpha(一共54个alpha)版本,今天终于发布了beta.0版本了
快速入门
目录结构
/angular2-quickstart/
/angular2-quickstart/app/
/angular2-quickstart/app/boot.ts
/angular2-quickstart/app/app.component.ts
/angular2-quickstart/index.htm
/angular2-quickstart/package.json
/angular2-quickstart/tsconfig.json代码
tsconfig.json
{
"compilerOptions": {
"target": "ES5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules"
]
}
package.json
{
"name": "angular2-quickstart",
"version": "1.0.0",
"scripts": {
"tsc": "tsc",
"tsc:w": "tsc -w",
"lite": "lite-server",
"go": "concurrent \"npm run tsc:w\" \"npm run lite\" "
},
"license": "ISC",
"dependencies": {
"angular2": "2.0.0-beta.0",
"systemjs": "0.19.6",
"es6-promise": "^3.0.2",
"es6-shim": "^0.33.3",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.0",
"zone.js": "0.5.10"
},
"devDependencies": {
"concurrently": "^1.0.0",
"lite-server": "^1.3.1",
"typescript": "^1.7.3"
}
}
index.html
<html>
<head>
<title>Angular 2 QuickStart</title>
<!-- 1. Load libraries -->
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<!-- 2. Configure SystemJS -->
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('app/boot')
.then(null, console.error.bind(console));
</script>
</head>
<!-- 3. Display the application -->
<body>
<my-app>Loading...</my-app>
</body>
</html>
app.component.ts
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
})
export class AppComponent { }
boot.ts
import {bootstrap} from 'angular2/platform/browser'
import {AppComponent} from './app.component'
bootstrap(AppComponent);
执行配置
在angular2-quickstart目录执行:npm install
执行程序
在angular2-quickstart目录执行:npm run go
总结
Angular在第一版AngularJS的时候就已经有很多项目使用并且证明这个是一个非常好的框架,现在升级到了第二版Angular 2,支持typescript语法,推荐大家学习并且尝试Angular 2。并且欢迎大家订阅我的开发者头条Angular2不是迷信