使用VS Code开发AngularJS 2 第一个应用程序

目录

  • 运行环境

  • 创建项目

  • 安装依赖包

  • 创建TypeScript应用程序

  • 配置应用程序

  • 运行应用程序

运行环境

运行环境:

  • Windows 10
  • Node 6.7.0

  • npm 3.10.8

  • TypeScript 2.0.3

创建项目

  • 1、创建文件夹:angular2-quickstart,启动VS Code,打开刚创建的文件夹:angular2-quickstart。
  • 2、在根文件夹(angular2-quickstart)下,创建package.json文件:
{"name": "angular-quickstart","version": "1.0.0","scripts": {"start": "tsc && concurrently \"tsc -w\" \"lite-server\" ","lite": "lite-server","postinstall": "typings install","tsc": "tsc","tsc:w": "tsc -w","typings": "typings"},"license": "ISC","dependencies": {"@angular/common": "~2.0.2","@angular/compiler": "~2.0.2","@angular/core": "~2.0.2","@angular/forms": "~2.0.2","@angular/http": "~2.0.2","@angular/platform-browser": "~2.0.2","@angular/platform-browser-dynamic": "~2.0.2","@angular/router": "~3.0.2","@angular/upgrade": "~2.0.2","angular-in-memory-web-api": "~0.1.5","bootstrap": "^3.3.7","core-js": "^2.4.1","reflect-metadata": "^0.1.8","rxjs": "5.0.0-beta.12","systemjs": "0.19.39","zone.js": "^0.6.25"},"devDependencies": {"concurrently": "^3.1.0","lite-server": "^2.2.2","typescript": "^2.0.3","typings": "^1.4.0"}
}
  • 3、在根文件夹(angular2-quickstart)下,创建tsconfig.json文件:
{"compilerOptions": {"target": "es5","module": "commonjs","moduleResolution": "node","sourceMap": true,"emitDecoratorMetadata": true,"experimentalDecorators": true,"removeComments": false,"noImplicitAny": false}
}
  • 4、在根文件夹(angular2-quickstart)下,创建typings.json文件:
{"globalDependencies": {"core-js": "registry:dt/core-js#0.0.0+20160725163759","jasmine": "registry:dt/jasmine#2.2.0+20160621224255","node": "registry:dt/node#6.0.0+20160909174046"}
}
  • 5、在根文件夹(angular2-quickstart)下,创建systemjs.config.js(JavaScript脚本)文件:
/*** System configuration for Angular samples* Adjust as necessary for your application needs.*/
(function(global) {System.config({paths: {// paths serve as alias'npm:': 'node_modules/'},// map tells the System loader where to look for thingsmap: {// our app is within the app folderapp: 'app',// angular bundles'@angular/core': 'npm:@angular/core/bundles/core.umd.js','@angular/common': 'npm:@angular/common/bundles/common.umd.js','@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js','@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js','@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js','@angular/http': 'npm:@angular/http/bundles/http.umd.js','@angular/router': 'npm:@angular/router/bundles/router.umd.js','@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',// other libraries'rxjs': 'npm:rxjs','angular-in-memory-web-api': 'npm:angular-in-memory-web-api',},// packages tells the System loader how to load when no filename and/or no extensionpackages: {app: {main: './main.js',defaultExtension: 'js'},rxjs: {defaultExtension: 'js'},'angular-in-memory-web-api': {main: './index.js',defaultExtension: 'js'}}});
})(this);

文件结构:

|_ angular2-quickstart
|_ app
| |_ app.component.ts
| |_ main.ts
|_ node_modules ...
|_ typings ...
|_ index.html
|_ package.json
|_ tsconfig.json
|_ typings.json

安装依赖包(最关键一步)

  • 使用 npm 命令来安装 package.json 中列出的依赖包。在命令行 cmd 窗口,输入:cd angular2-quickstart,进入angular2-quickstar文件夹下,输入下列命令:
npm install

创建TypeScript应用程序

  • 1、在VS Code中,在根文件夹(angular2-quickstart)下,创建app子文件夹。
  • 2、在子app文件夹下,创建TypeScript文件app.module.ts:
import { NgModule }      from '@angular/core';import { BrowserModule } from '@angular/platform-browser';import { AppComponent }   from './app.component';@NgModule({imports:      [ BrowserModule ],declarations: [ AppComponent ],bootstrap:    [ AppComponent ]
})export class AppModule { }
  • 3、在子app文件夹下,创建TypeScript文件app.component.ts:
import { Component } from '@angular/core';@Component({selector: 'my-app',template: '<h1>我的第一个 AngularJS 2 应用程序</h1>'
})export class AppComponent { }
  • 4、在子app文件夹下,创建TypeScript文件main.ts:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';import { AppModule } from './app.module';const platform = platformBrowserDynamic();platform.bootstrapModule(AppModule);
  • 5、在根文件夹(angular2-quickstart)下,创建html文件index.html:
<html><head><title>Angular QuickStart</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="styles.css"><!-- 1. Load libraries --><!-- Polyfill(s) for older browsers --><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/systemjs/dist/system.src.js"></script><!-- 2. Configure SystemJS --><script src="systemjs.config.js"></script><script>System.import('app').catch(function(err) {console.error(err);});</script>
</head>
<!-- 3. Display the application --><body><my-app>Loading...</my-app>
</body></html>
  • 6、在根文件夹(angular2-quickstart)下,创建css文件styles.css:
/* Master Styles */h1 {color: #369;font-family: Arial, Helvetica, sans-serif;font-size: 250%;
}h2,
h3 {color: #444;font-family: Arial, Helvetica, sans-serif;font-weight: lighter;
}body {margin: 2em;
}

配置应用程序

  • 1、在VS Code中,在根文件夹(angular2-quickstart)下,创建.vscode子文件夹。
  • 2、在.vscode子文件夹下,创建settings.json文件:
// 将设置放入此文件中以覆盖默认值和用户设置。
{"typescript.tsdk": "node_modules/typescript/lib",// ts 项目, 隐藏 .js 和 .js.map 文件"files.exclude": {"node_modules": true,"**/*.js": { "when": "$(basename).ts" },"**/*.js.map": true}}
  • 3、在.vscode子文件夹下,创建tasks.json文件:
{// See https://go.microsoft.com/fwlink/?LinkId=733558// for the documentation about the tasks.json format"version": "0.1.0","command": "cmd","isShellCommand": true,"showOutput": "always","args": ["/C npm start"]
}

运行应用程序

  • 至此,配置完毕,按 Ctrl + Shift + B 编译,程序将会将Typescript编译成 Javascript ,同时启动一个 lite-server, 加载我们编写的index.html。 显示:我的第一个 Angular 2 应用程序

参考资料

  • 快速起步
  • 打造AngularJs2.0开发环境
  • AngularJs 2 快速入门
  • AngularJS2.0起步

转载于:https://www.cnblogs.com/junxian_chen/p/5940481.html

使用VS Code开发AngularJS 2 第一个应用程序相关推荐

  1. 用Kotlin开发您的第一个应用程序| Android与Kotlin

    In the previous article, we learned how to setup Kotlin in the android studio? Now moving to journey ...

  2. 使用Eclipse开发Spring的第一个简单程序

    使用Eclipse开发Spring的第一个简单程序 本篇文章将通过一个简单的入门程序向读者演示Spring框架的使用过程,具体如下: 使用Eclipse创建Web应用并导入JAR包 使用Eclipse ...

  3. 使用VS Code开发 调试.NET Core 应用程序

    使用VS Code开发 调试.NET Core RC2应用程序,由于.NET Core 目前还处于预览版. 本文使用微软提供的示例进行开发及调试. https://github.com/aspnet/ ...

  4. AngularJS实战第一章

    AngularJS实战 作者:kimmking.大漠穷秋.任富飞 问题反馈:kimmking@163.com 快速上手 AngularJS介绍-AngularJS的前世今生 AngularJS核心特性 ...

  5. 初级开发人员的缺点_在您作为初级开发人员的第一年获得此建议

    初级开发人员的缺点 Are you a junior developer embarking on your software development career? 您是从事软件开发事业的初级开发人 ...

  6. studio 热重载应用_使用VS Code开发Flutter应用,体验热重载技术

    如果你和我一样也是一个开发人员,你有没有遇到过下面的问题: 你打开Android Studio或者XCode进行开发,发现过不了多久机器的内存就被"吃"光了,随着程序界面的越来越复 ...

  7. 从unity到unreal4 虚幻4学习笔记 一 : ue4与vs studio、vs code开发环境的安装与配置

    前言 学习ue4的理由 我是个资深unity玩家,自认为可以使用unity做任何事.对虚幻的仰慕纯属技术信仰,懂的都懂不多解释.我并不打算放弃unity,正所谓艺多不压身,多储备点技术栈也没坏处. u ...

  8. 《软件工具》手把手教你使用Visual Studio Code开发C/C++(Windows)

    C/C++的开发工具很多,微软的Visual Studio,QT等都是不错的选择,但是这些IDE都过于庞大,而且有很多IDE都是收费的.笔者这里推荐GCC+Make+代码编辑器的方式来开发C/C++, ...

  9. Spring Boot(1)——开发你的第一款Spring Boot应用(Edition1)

    Spring Boot(1)--开发你的第一款Spring Boot应用(Edition1) 准备工作: java:java 8 或者 java 9: Spring框架:5.0.8.RELEASE或以 ...

最新文章

  1. 理解Linux系统负荷
  2. SAP LSMW 物料主数据Basic Data Text数据的导入
  3. 64位虚拟机安装64位ubuntu出现问题
  4. ESX 4 不能使用SSH登录的解决
  5. python旋转矩阵_python实现回旋矩阵方式(旋转矩阵)
  6. SDNU 1019.礼物(水题)
  7. SAP Data Intelligence API如何获得Access Token - no authentication means found
  8. 对VMware自动安装linux系统说“不”!
  9. P2619 [国家集训队]Tree I(WQS二分/带权二分/最小生成树)
  10. android webview 获取 title,【报Bug】app webview 安卓机 title显示问题
  11. SPT20 协议_【笔试时间有变】关于国家电网三方协议的那些事!
  12. 英语作业(general version an narrow version about sth)
  13. 大屏样式(全屏禁止滚动)
  14. 战地一的服务器在哪个文件夹,战地1怎么加入服务器 战地1加入服务器方法
  15. Spark出租车数据实验实用说明书
  16. URI和URL的区别与联系
  17. 教育培训机构如何利用小程序招生?
  18. 最新免费网站空间申请网站集合
  19. 在Windows中查看文件的MD5值
  20. python--列表、数组扁平化

热门文章

  1. 关于window.scroll系列方法汇总 滚动到指定元素位置
  2. linux进程网络监控,linux下的进程、网络、性能监控命令
  3. 魔兽世界怀旧服服务器显示配置,《魔兽世界怀旧服》配置要求是什么 什么配置能玩...
  4. afterlogic 7.0.1 php,免费webmail 7.0.1(after logic 最后一个免费版本)
  5. ubuntu装后的常用软件的安装与配置
  6. 代码随想录Day04 | LeetCode24. 两两交换链表中的节点、LeetCode19. 删除链表的倒数第N个节点、LeetCode160. 链表相交、LeetCode142. 环形链表Ⅱ
  7. php 验证 繁体,验证码上中文字是繁体
  8. oracle进行排序,oracle排序的几种方法
  9. 《算法和数据结构》排序篇
  10. 备考PMP的程序员注意了!!!13张PMPBook思维导图免费送上,没有套路,直接领取