5 分鐘從0搭建一個ng2項目demo
https://angular.io/docs/js/latest/quickstart.html html
你運氣真好,居然看到了這篇文章,你省事了,一分鐘讓你完成,請點擊https://github.com/1329555958/angular2-quickstartnode
假定你已經具有了nodejs環境;git
|----app | |----app.component.js | |----boot.js |----index.html |----package.json
npm install
在package.json同級目錄下執行(我僞裝你不知道在哪裏執行)此時你發現你的目錄多出了node_modules及下面一些目錄;
運行npm start
,你的默認瀏覽器會打開一個頁面,http://localhost:3000 ,若是沒有,能夠聯繫我;es6
恭喜你!你很棒,累了吧,休息會,稍後咱們再細聊具體細節!github
package.json
npm
{ "name": "angular2-quickstart", "version": "1.0.0", "scripts": { "start": "npm run lite", "lite": "lite-server" }, "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": { "lite-server": "^1.3.1" }}
app.component.js
json
(function (app) { app.AppComponent = ng.core .Component({ selector: '.my-app',//簡單的CSS選擇器 template: '<h1>My First Angular 2 App</h1>' }) .Class({ constructor: function () { } });})(window.app || (window.app = {}));
boot.js
bootstrap
(function (app) { document.addEventListener('DOMContentLoaded', function () { ng.platform.browser.bootstrap(app.AppComponent); });})(window.app || (window.app = {}));
index.html
promise
<!DOCTYPE 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/rxjs/bundles/Rx.umd.js"></script> <script src="node_modules/angular2/bundles/angular2-all.umd.js"></script> <!-- 2. Load our 'modules' --> <script src='app/app.component.js'></script> <script src='app/boot.js'></script></head><!-- 3. Display the application --><body><div class="my-app">Loading...</div></body></html>