0.創(chuàng)建配置文件
使用DOS命令切換到目標(biāo)目錄下,運(yùn)行命令
mkdir angular-quickstart
cd angular-quickstart
創(chuàng)建并轉(zhuǎn)到目錄中.
1.手動(dòng)編寫配置文件
新建文件 package.json
寫入配置
{
"name": "angular2-quickstart",
"version": "1.0.0",
"scripts": {
"start": "npm run lite",
"lite": "lite-server"
},
"license": "ISC",
"dependencies": {
"@angular/common": "2.0.0",
"@angular/compiler": "2.0.0",
"@angular/core": "2.0.0",
"@angular/forms": "2.0.0",
"@angular/http": "2.0.0",
"@angular/platform-browser": "2.0.0",
"@angular/platform-browser-dynamic": "2.0.0",
"@angular/router": "3.0.0",
"@angular/upgrade": "2.0.0",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.12",
"zone.js": "^0.6.23",
"angular2-in-memory-web-api": "0.0.20",
"bootstrap": "^3.3.6"
},
"devDependencies": {
"concurrently": "^2.0.0",
"lite-server": "^2.2.0"
}
}
2.安裝npm //這個(gè)過程好像可以省略
如圖
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install
3.創(chuàng)建js文件
首先新建app目錄
在app目錄下新建組件文件:app.component.js
(function(app) {
app.AppComponent =
ng.core.Component({
selector: 'my-app',
template: '<h1>我的第一個(gè) Angular 應(yīng)用</h1>'
})
.Class({
constructor: function() {}
});
})(window.app || (window.app = {}));
新建模塊文件 :app.module.js
(function(app) {
app.AppModule =
ng.core.NgModule({
imports: [ ng.platformBrowser.BrowserModule ],
declarations: [ app.AppComponent ],
bootstrap: [ app.AppComponent ]
})
.Class({
constructor: function() {}
});
})(window.app || (window.app = {}));
新建啟動(dòng)文件 main.js
(function(app) {
document.addEventListener('DOMContentLoaded', function() {
ng.platformBrowserDynamic
.platformBrowserDynamic()
.bootstrapModule(app.AppModule);
});
})(window.app || (window.app = {}));
4.入口文件
在Angular目錄下新建路口文件 index.html
<html>
<head>
<meta charset="utf-8">
<title>Angular 2 實(shí)例 - 菜鳥教程(runoob.com)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<!-- 1. 載入庫 -->
<!-- IE 需要 polyfill -->
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/@angular/core/bundles/core.umd.js"></script>
<script src="node_modules/@angular/common/bundles/common.umd.js"></script>
<script src="node_modules/@angular/compiler/bundles/compiler.umd.js"></script>
<script src="node_modules/@angular/platform-browser/bundles/platform-browser.umd.js"></script>
<script src="node_modules/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js"></script>
<!-- 2. 載入 'modules' -->
<script src='app/app.component.js'></script>
<script src='app/app.module.js'></script>
<script src='app/main.js'></script>
</head>
<!-- 3. 顯示應(yīng)用 -->
<body>
<my-app>Loading...</my-app>
</body>
</html>
5.完成 及 其他
我才不會(huì)說我玩了一早上沒玩出來
主要問題終于js文件一定要下載好S汀1嘈帧!