博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
angular入门
阅读量:6842 次
发布时间:2019-06-26

本文共 4259 字,大约阅读时间需要 14 分钟。

angular2 学习入门第一课

步骤

  • Install Node.js

  • 创建应用程序的项目文件夹和定义包的依赖关系和特殊项目设置

  • Create the app’s Angular root component

  • Add main.ts, identifying the root component to Angular

  • Add index.html, the web page that hosts the application

  • Build and run the app

文件

创建文件

touch package.jsontouch tsconfig.json touch typings.jsontouch systemjs.config.jstouch index.htmltouch styles.cssmkdir apptouch app/app.component.tstouch app/main.ts
package.json {  "name": "angular2-quickstart",  "version": "1.0.0",  "scripts": {    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",    "lite": "lite-server",    "postinstall": "typings install",    "tsc": "tsc",    "tsc:w": "tsc -w",    "typings": "typings"  },  "license": "ISC",  "dependencies": {    "@angular/common": "2.0.0-rc.4",    "@angular/compiler": "2.0.0-rc.4",    "@angular/core": "2.0.0-rc.4",    "@angular/forms": "0.2.0",    "@angular/http": "2.0.0-rc.4",    "@angular/platform-browser": "2.0.0-rc.4",    "@angular/platform-browser-dynamic": "2.0.0-rc.4",    "@angular/router": "3.0.0-beta.1",    "@angular/router-deprecated": "2.0.0-rc.2",    "@angular/upgrade": "2.0.0-rc.4",    "systemjs": "0.19.27",    "core-js": "^2.4.0",    "reflect-metadata": "^0.1.3",    "rxjs": "5.0.0-beta.6",    "zone.js": "^0.6.12",    "angular2-in-memory-web-api": "0.0.14",    "bootstrap": "^3.3.6"  },  "devDependencies": {    "concurrently": "^2.0.0",    "lite-server": "^2.2.0",    "typescript": "^1.8.10",    "typings":"^1.0.4"  }}
tsconfig.json {  "compilerOptions": {    "target": "es5",    "module": "commonjs",    "moduleResolution": "node",    "sourceMap": true,    "emitDecoratorMetadata": true,    "experimentalDecorators": true,    "removeComments": false,    "noImplicitAny": false  }}
typings.json{  "globalDependencies": {    "core-js": "registry:dt/core-js#0.0.0+20160602141332",    "jasmine": "registry:dt/jasmine#2.2.0+20160621224255",    "node": "registry:dt/node#6.0.0+20160621231320"  }}
systemjs.config.js/** * System configuration for Angular 2 samples * Adjust as necessary for your application needs. */(function(global) {  // map tells the System loader where to look for things  var map = {    'app':                        'app', // 'dist',    '@angular':                   'node_modules/@angular',    'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',    'rxjs':                       'node_modules/rxjs'  };  // packages tells the System loader how to load when no filename and/or no extension  var packages = {    'app':                        { main: 'main.js',  defaultExtension: 'js' },    'rxjs':                       { defaultExtension: 'js' },    'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },  };  var ngPackageNames = [    'common',    'compiler',    'core',    'forms',    'http',    'platform-browser',    'platform-browser-dynamic',    'router',    'router-deprecated',    'upgrade',  ];  // Individual files (~300 requests):  function packIndex(pkgName) {    packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };  }  // Bundled (~40 requests):  function packUmd(pkgName) {    packages['@angular/'+pkgName] = { main: '/bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };  }  // Most environments should use UMD; some (Karma) need the individual index files  var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;  // Add package entries for angular packages  ngPackageNames.forEach(setPackageConfig);  var config = {    map: map,    packages: packages  };  System.config(config);})(this);

编译

npm installnpm run typings install

Our first Angular component

mkdir apptouch app/app.component.tsimport { Component } from '@angular/core';@Component({  selector: 'my-app',  template: '

My First Angular 2 App

'})export class AppComponent { }touch app/main.tsimport { bootstrap } from '@angular/platform-browser-dynamic';import { AppComponent } from './app.component';bootstrap(AppComponent);touch index.html
      Angular 2 QuickStart    
Loading...

style.css

h1 {  color: #369;  font-family: Arial, Helvetica, sans-serif;  font-size: 250%;}body {  margin: 2em;}

Build and run the app!

npm start

转载地址:http://iqdul.baihongyu.com/

你可能感兴趣的文章
突破360防黑加固添加用户
查看>>
数据仓库建模方法初步
查看>>
Active Directory 回收站配置篇
查看>>
ubuntu 11.10 体验
查看>>
MS UC 2013-0-虚拟机-标准化-部署-2-模板机-制作-5
查看>>
隐藏nginx、apache与php版本号
查看>>
【STM32 .Net MF开发板学习-08】远程PLC读写控制
查看>>
Lync 小技巧-12-同台服务器删除Lync Server 2010安装Lync Server 2013
查看>>
【STM32 .Net MF开发板学习-17】Wifi遥控智能小车
查看>>
做程序,要“专注”和“客观”
查看>>
运维常用表格
查看>>
6.VMware View 4.6安装与部署-view桌面克隆与分配
查看>>
Azure恢复服务-DPM联机备份SQL数据库
查看>>
大分区使用xfs文件系统存储备份遇到的问题
查看>>
记录-三步走FreeMarker Template学习
查看>>
vsts项目管理理论基础——MSF
查看>>
Cocos2d-x Eclipse下程序运行产生错误Effect initCheck() returned -1
查看>>
Unity依赖注入使用详解
查看>>
Windows GVim
查看>>
kernel_read【转】
查看>>