angularjs 2.0 简单入门1
一:首先要写json文件,并下载所有的包
1,在任意目录下新建文件夹 命名为angular2Dome,也可以使用命令 mkdir angular2Dome 回车。
2,在angular2Dome文件夹内创建一个文件叫 package.json或使用命令 echo>package.json
3,将以下内容复制到package.json
{
"name": "angular2-quickstart",
"version": "1.0.0",
"scripts": {
"tsc": "tsc",
"tsc:w": "tsc -w",
"lite": "lite-server",
"start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
},
"license": "ISC",
"dependencies": {
"angular2": "2.0.0-beta.3",
"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.11"
},
"devDependencies": {
"concurrently": "^1.0.0",
"lite-server": "^2.0.1",
"typescript": "^1.7.5"
}
}
4,使用命令 定位到angular2Dome目录下 输入 npm install 等待·
5,配置Typescript(ts).
6,我们在angular2Dome 下创建一个tsconfig.json,并复制以下内容到文件中。
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules"
]
}
二、写ts源码
1,在angular2Dome目录下创建文件夹app,并在app文件夹里创建一个文件app.component.ts
2,将以下内容复制到app.component.ts中
import {Component} from 'angular2/core'; @Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
})
export class AppComponent { }
注:class前的 export 这个动作把ts文件变成了一个组件,使别处可以import并使用它。
3,在app目录下创建文件 main.ts
4,复制以下内容到main.ts
import {bootstrap} from 'angular2/platform/browser'
import {AppComponent} from './app.component' bootstrap(AppComponent);
三,写html
1,在angular2Dome目录下创建html文件,命名为index.html
2,复制以下内容到index.html
<html>
<head>
<title>Angular 2 QuickStart</title>
<meta name="viewport" content="width=device-width, initial-scale=1"> <!-- 1. Load libraries -->
<!-- IE required polyfills, in this exact order -->
<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/systemjs/dist/system-polyfills.js"></script> <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/main')
.then(null, console.error.bind(console));
</script>
</head> <!-- 3. Display the application -->
<body>
<my-app>Loading...</my-app>
</body> </html>
简单讲述以下,在index.html分为三块,第一 引入必要的js文件,它们都讯在npm下载好的目录下,第二 配置了SystemJS,并在里面import了我们写好的main.ts,main.ts里提供了代码的入口即bootstrap。第三块就是显示出来我们最开始写的app.component.ts,在app.component.ts的代码里有一句是selector:'my-app',所在html里这个组件就用<my-app></my-app>表示,这个标签显示的内容就是 template:'<h1>My First Angular2 App</h1>'中的<h1>My First Angular2 App</h1>',而那个Loading...则会显示在JS文件加载完之前,加载之后就会被 template里的内容替代。
四 编译运行
1,在angular2Dome 目录下命令输入npm start ,或 http-server 打开浏览器将看到结果。
selec替代,suoyitor:
angularjs 2.0 简单入门1的更多相关文章
- angularjs 2.0 快速开始
前言 angularjs2.0 如果发布,公司的项目会基于2.0开发,在1.0的时候就踩了好多坑,趁这2.0还没正式发布,赶紧踩下坑. 这篇文章是参考angularjs2.0 官方文档写的,开发环境需 ...
- [原创]MYSQL的简单入门
MYSQL简单入门: 查询库名称:show databases; information_schema mysql test 2:创建库 create database 库名 DEFAULT CHAR ...
- Okio 1.9简单入门
Okio 1.9简单入门 Okio库是由square公司开发的,补充了java.io和java.nio的不足,更加方便,快速的访问.存储和处理你的数据.而OkHttp的底层也使用该库作为支持. 该库极 ...
- 【java开发系列】—— spring简单入门示例
1 JDK安装 2 Struts2简单入门示例 前言 作为入门级的记录帖,没有过多的技术含量,简单的搭建配置框架而已.这次讲到spring,这个应该是SSH中的重量级框架,它主要包含两个内容:控制反转 ...
- Springmvc整合tiles框架简单入门示例(maven)
Springmvc整合tiles框架简单入门示例(maven) 本教程基于Springmvc,spring mvc和maven怎么弄就不具体说了,这边就只简单说tiles框架的整合. 先贴上源码(免积 ...
- Web---演示Servlet的相关类、表单多参数接收、文件上传简单入门
说明: Servlet的其他相关类: ServletConfig – 代表Servlet的初始化配置参数. ServletContext – 代表整个Web项目. ServletRequest – 代 ...
- HTML5简单入门系列(五)
前言 本篇将讲述HTML5的服务器发送事件(server-sent event) Server-Sent 事件 Server-Sent 事件是单向消息传递,指的是网页自动获取来自服务器的更新. 以前的 ...
- Asp.Net MVC3 简单入门第一季(三)详解Controller之Filter
前言 前面两篇写的比较简单,刚开始写这个系列的时候我面向的对象是刚开始接触Asp.Net MVC的朋友,所以写的尽量简单.所以写的没多少技术含量.把这些技术总结出来,然后一简单的方式让更多的人很好的接 ...
- Web Service简单入门示例
Web Service简单入门示例 我们一般实现Web Service的方法有非常多种.当中我主要使用了CXF Apache插件和Axis 2两种. Web Service是应用服务商为了解决 ...
随机推荐
- 【算法python实现】 -- 不同路径
原题:https://leetcode-cn.com/problems/unique-paths/ 问题描述 n行m列的表格,从a[0][0]出发,每次只能右移一步或者下移一步,求到a[n-1][m- ...
- MariaDB 连接查询与子查询(6)
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可MariaDB的目的是完全兼容MySQL,包括API和命令行,MySQL由于现在闭源了,而能轻松成为MySQ ...
- 说一下acad的bug及问题
using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk. ...
- es6新增Math方法
Math.trunc() 用于去除一个数的小数部分,只返回整数部分 Math.trunc(4.1) // 4 Math.trunc(4.9) // 4 Math.trunc(-4.1) // -4 ...
- Swift 里 Set(四)Testing for Membership
即contains操作 /// - Parameter member: An element to look for in the set. /// - Returns: `true` if `mem ...
- POJ 2485
#include<iostream> #define MAXN 505 #define inf 1000000000 using namespace std; typedef int el ...
- 06-03 Java 面向对象思想概述、开发设计特征,类和对象的定义使用,对象内存图
面向对象思想概述.开发设计特征 1:面向对象思想 面向对象是基于面向过程的编程思想. 面向过程:强调的是每一个功能的步骤 面向对象:强调的是对象,然后由对象去调用功能 2:面向对象的思想特点 A:是一 ...
- rpm安装JDK方法
由于版权原因,Linux发行版并没有包含官方版的Oracle JDK,必须自己从官网上下载安装.Oracle官网用Cookie限制下载方式,使得眼下只能用浏览器进行下载,使用其他方式可能会导致下载失败 ...
- javascript 获取当前浏览器窗口宽高
获取当前浏览器窗口宽度:document.documentElement.clientWidth;获取当前浏览器窗口高度:document.documentElement.clientHeight; ...
- Vue源码翻译之组件初始化。
废话不多说. 我们先来看看Vue的入口文件. import { initMixin } from './init' import { stateMixin } from './state' impor ...