2016-05-14 20:40:52 -04:00
|
|
|
|
block includes
|
|
|
|
|
include _util-fns
|
2016-05-19 05:21:12 -04:00
|
|
|
|
- var _Install = 'Install'
|
|
|
|
|
- var _InstallCn = '安装'
|
2016-05-14 20:40:52 -04:00
|
|
|
|
- var _prereq = 'Node.js'
|
|
|
|
|
- var _angular_browser_uri = '@angular/platform-browser-dynamic'
|
|
|
|
|
- var _angular_core_uri = '@angular/core'
|
2016-04-09 09:26:00 -04:00
|
|
|
|
|
2015-11-10 13:31:46 -05:00
|
|
|
|
:marked
|
2016-05-16 20:10:19 -04:00
|
|
|
|
Our QuickStart goal is to build and run a super-simple
|
|
|
|
|
Angular 2 application in #{_Lang}, and
|
2016-05-14 20:40:52 -04:00
|
|
|
|
establish a development environment for the remaining documentation samples
|
|
|
|
|
that also can be the foundation for real world applications.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
这份“快速起步”的目标是基于#{_Lang}构建并运行一个超级简单的Angular应用,
|
|
|
|
|
并为文档其余部分的范例代码建立开发环境。
|
|
|
|
|
同时,它还可以作为构建真实应用的基础。
|
2016-05-14 20:40:52 -04:00
|
|
|
|
|
|
|
|
|
.callout.is-helpful
|
|
|
|
|
header Don't want #{_Lang}?
|
2016-05-19 04:32:43 -04:00
|
|
|
|
header 不喜欢#{_Lang}?
|
2016-05-14 20:40:52 -04:00
|
|
|
|
p.
|
|
|
|
|
Although we're getting started in #{_Lang}, you can also write Angular 2 apps
|
|
|
|
|
in #{_docsFor == 'ts' ? 'Dart' : 'TypeScript'} and JavaScript.
|
|
|
|
|
Just select either of those languages from the combo-box in the banner.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
p.
|
|
|
|
|
虽然我们正在用#{_Lang},但你也可以用#{_docsFor == 'ts' ? 'Dart' : 'TypeScript'}和JavaScript来写Angular 2应用。
|
2016-05-25 05:08:55 -04:00
|
|
|
|
只要从Banner区的下拉框选择想用的那种语言就可以了。
|
2016-05-14 20:40:52 -04:00
|
|
|
|
|
|
|
|
|
h1 Try it!
|
2016-05-19 04:32:43 -04:00
|
|
|
|
h1 试试!
|
2016-05-14 20:40:52 -04:00
|
|
|
|
p
|
2016-05-20 19:18:58 -04:00
|
|
|
|
| Try the #[+liveExampleLink2()] which loads the sample app
|
2016-05-14 20:40:52 -04:00
|
|
|
|
+ifDocsFor('ts')
|
|
|
|
|
| in #[a(href="http://plnkr.co/" title="Plunker" target="_blank") plunker]
|
|
|
|
|
| and displays the simple message:
|
2016-05-19 04:32:43 -04:00
|
|
|
|
p
|
2016-05-19 05:21:12 -04:00
|
|
|
|
| 试试#[+liveExampleLink2('在线范例', 'quickstart')],它将把此范例加载
|
2016-05-19 04:32:43 -04:00
|
|
|
|
+ifDocsFor('ts')
|
2016-05-19 05:21:12 -04:00
|
|
|
|
| 到 #[a(href="http://plnkr.co/" title="Plunker" target="_blank") plunker]中
|
|
|
|
|
| 并显示一条简单的消息:
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2015-12-10 21:29:14 -05:00
|
|
|
|
figure.image-display
|
2016-05-18 01:30:07 -04:00
|
|
|
|
img(src='/resources/images/devguide/quickstart/my-first-app.png' alt="“快速起步”应用的输出")
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
h1 Build this app!
|
2016-05-19 04:32:43 -04:00
|
|
|
|
h1 构建此应用!
|
2015-12-10 21:29:14 -05:00
|
|
|
|
:marked
|
2016-05-16 20:10:19 -04:00
|
|
|
|
- [Prerequisite](#prereq): Install #{_prereq}
|
2016-05-19 04:32:43 -04:00
|
|
|
|
- [环境准备](#prereq): 安装#{_prereq}
|
2016-05-16 20:10:19 -04:00
|
|
|
|
- [Step 1](#create-and-configure): Create the app’s project folder and
|
2016-05-14 20:40:52 -04:00
|
|
|
|
define package dependencies and special project setup
|
2016-05-19 04:32:43 -04:00
|
|
|
|
- [步骤1](#create-and-configure):创建本应用的项目文件夹,并且定义包的依赖以及特别的项目设置。
|
2016-05-16 20:10:19 -04:00
|
|
|
|
- [Step 2](#root-component): Create the app’s Angular root component
|
2016-05-19 04:32:43 -04:00
|
|
|
|
- [步骤2](#root-component): 创建本应用的Angular根组件
|
2016-05-16 20:10:19 -04:00
|
|
|
|
- [Step 3](#main): Add `main.#{_docsFor}`, identifying the root component to Angular
|
2016-05-19 04:32:43 -04:00
|
|
|
|
- [步骤3](#main):添加`main.#{_docsFor}`,用来告诉Angular哪个是根组件。
|
2016-05-16 20:10:19 -04:00
|
|
|
|
- [Step 4](#index): Add `index.html`, the web page that hosts the application
|
2016-05-19 04:32:43 -04:00
|
|
|
|
- [步骤4](#index):添加`index.html`,本应用的宿主页面。
|
2016-05-16 20:10:19 -04:00
|
|
|
|
- [Step 5](#build-and-run): Build and run the app
|
2016-05-19 04:32:43 -04:00
|
|
|
|
- [步骤5](#build-and-run):构建并运行本应用
|
2016-05-14 20:40:52 -04:00
|
|
|
|
- [Make some changes to the app](#make-some-changes)
|
2016-05-19 04:32:43 -04:00
|
|
|
|
- [对本应用做一些修改](#make-some-changes)
|
2016-05-14 20:40:52 -04:00
|
|
|
|
- [Wrap up](#wrap-up)
|
2016-05-19 04:32:43 -04:00
|
|
|
|
- [收工](#wrap-up)
|
2016-02-12 20:54:22 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
.l-main-section
|
|
|
|
|
h2#prereq Prerequisite: #{_prereq}
|
2016-05-19 04:32:43 -04:00
|
|
|
|
h2#prereq 环境准备:#{_prereq}
|
2016-05-14 20:40:52 -04:00
|
|
|
|
|
|
|
|
|
block setup-tooling
|
2015-12-10 21:29:14 -05:00
|
|
|
|
:marked
|
2016-05-14 20:40:52 -04:00
|
|
|
|
Install **[Node.js® and npm](https://nodejs.org/en/download/)**
|
|
|
|
|
if they are not already on your machine.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
如果你的机器上还没有**[Node.js®和npm](https://nodejs.org/en/download/)**,请安装它们。
|
2016-05-21 12:36:27 -04:00
|
|
|
|
.l-sub-section
|
|
|
|
|
:marked
|
2016-05-28 16:49:13 -04:00
|
|
|
|
**Verify that you are running at least node `v5.x.x` and npm `3.x.x`**
|
2016-05-21 12:36:27 -04:00
|
|
|
|
by running `node -v` and `npm -v` in a terminal/console window.
|
2016-05-28 16:49:13 -04:00
|
|
|
|
Older versions produce errors.
|
2016-05-25 06:13:25 -04:00
|
|
|
|
|
|
|
|
|
**在终端窗口运行`node -v`和`npm -v`,来确认你的node版本为`v5.x.x`,npm版本为`3.x.x`**。
|
2016-05-30 08:58:59 -04:00
|
|
|
|
老版本会出错。
|
2016-05-25 06:13:25 -04:00
|
|
|
|
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
block download-source
|
|
|
|
|
.l-main-section
|
|
|
|
|
.callout.is-helpful
|
|
|
|
|
header Download the source
|
2016-05-19 04:32:43 -04:00
|
|
|
|
header 下载源码
|
2016-05-14 20:40:52 -04:00
|
|
|
|
:marked
|
2016-05-16 20:10:19 -04:00
|
|
|
|
Instead of following each step of these instructions, we can
|
|
|
|
|
[download the QuickStart source](https://github.com/angular/quickstart/blob/master/README.md)
|
2016-05-14 20:40:52 -04:00
|
|
|
|
from github and follow its brief instructions.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
如果不想跟着这里的操作指南来一步步儿做,我们也可以从github[下载“快速起步”的源码](https://github.com/angular/quickstart/blob/master/README.md),这样只要注意那些操作要点就行了。
|
2016-05-14 20:40:52 -04:00
|
|
|
|
|
|
|
|
|
.l-main-section
|
2016-02-12 20:54:22 -05:00
|
|
|
|
button(class="verbose off md-primary md-button md-ink-ripple", type="button", onclick="verbose(false)").
|
|
|
|
|
Hide explanations
|
2016-05-13 01:29:08 -04:00
|
|
|
|
button(class="verbose off md-primary md-button md-ink-ripple", type="button", onclick="verbose(false)").
|
2016-03-03 11:02:33 -05:00
|
|
|
|
隐藏解释
|
2016-02-12 20:54:22 -05:00
|
|
|
|
button(class="verbose on md-primary md-button md-ink-ripple", type="button", onclick="verbose(true)").
|
|
|
|
|
View explanations
|
2016-05-13 01:29:08 -04:00
|
|
|
|
button(class="verbose on md-primary md-button md-ink-ripple", type="button", onclick="verbose(true)").
|
2016-03-03 11:02:33 -05:00
|
|
|
|
查看解释
|
2016-02-12 20:54:22 -05:00
|
|
|
|
.l-verbose-section
|
|
|
|
|
:marked
|
|
|
|
|
*Explanations* describe the concepts and reasons behind the instructions.
|
|
|
|
|
Explanations have a thin border on the left like *this* block of text.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
2016-05-19 05:21:12 -04:00
|
|
|
|
*解释*,负责描述概念和操作指南背后的理由。解释在左侧有一个细边框,就像*这块儿文字*。
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
|
|
|
|
Click *Hide Explanations* to show only the instructions.
|
2016-05-16 20:10:19 -04:00
|
|
|
|
Click *View Explanations* to see everything again.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
点击*隐藏解释*按钮把*解释*隐藏掉,点击*显示解释*按钮再把它显示出来。
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
.l-sub-section
|
2015-11-10 13:31:46 -05:00
|
|
|
|
:marked
|
2016-05-14 20:40:52 -04:00
|
|
|
|
We'll see many code blocks as we build the QuickStart app. They're all easy to copy and paste:
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
当我们构建这个“快速起步”应用时,会看到很多代码块儿。它们都很方便拷贝和粘贴:
|
2016-05-14 20:40:52 -04:00
|
|
|
|
code-example(format="nocode").
|
2016-05-19 04:32:43 -04:00
|
|
|
|
点击右侧的图标,来把代码片段拷贝到剪贴板 ==>
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2015-10-16 00:51:13 -04:00
|
|
|
|
.l-main-section
|
2016-05-16 20:10:19 -04:00
|
|
|
|
h2#create-and-configure Step 1: Create and configure the project
|
2016-05-19 04:32:43 -04:00
|
|
|
|
h2#create-and-configure 步骤1:创建并配置项目
|
2016-02-12 20:54:22 -05:00
|
|
|
|
|
2016-05-19 05:21:12 -04:00
|
|
|
|
- var _package_and_config_files = _docsFor == 'dart' ? 'pubspec.yaml' : 'package definition and configuration files'
|
|
|
|
|
- var _package_and_config_filesCn = _docsFor == 'dart' ? 'pubspec.yaml' : '包定义与配置文件'
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2015-12-10 21:29:14 -05:00
|
|
|
|
:marked
|
2016-05-14 20:40:52 -04:00
|
|
|
|
In this step we:
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
在这一步,我们将:
|
2016-05-16 20:10:19 -04:00
|
|
|
|
* [(a) Create the project folder](#create-the-project-folder)
|
2016-05-19 04:32:43 -04:00
|
|
|
|
* [(a) 创建项目目录](#create-the-project-folder)
|
2016-05-16 20:10:19 -04:00
|
|
|
|
* [(b) Add #{_package_and_config_files}](#add-config-files)
|
2016-05-19 05:21:12 -04:00
|
|
|
|
* [(b) 添加#{_package_and_config_filesCn}](#add-config-files)
|
2016-05-16 20:10:19 -04:00
|
|
|
|
* [(c) #{_Install} packages](#install-packages)
|
2016-05-19 05:21:12 -04:00
|
|
|
|
* [(c) #{_InstallCn}依赖包](#install-packages)
|
2016-03-07 08:42:10 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
h3 (a) Create the project folder
|
2016-05-19 04:32:43 -04:00
|
|
|
|
h3 (a) 创建项目文件夹
|
2016-02-12 20:54:22 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
code-example(language="sh").
|
2015-12-10 21:29:14 -05:00
|
|
|
|
mkdir angular2-quickstart
|
|
|
|
|
cd angular2-quickstart
|
2016-02-12 20:54:22 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
h3#add-config-files (b) Add #{_package_and_config_files}
|
2016-05-19 05:21:12 -04:00
|
|
|
|
h3#add-config-files (b) 添加#{_package_and_config_filesCn}
|
2016-05-14 20:40:52 -04:00
|
|
|
|
block package-and-config-files
|
|
|
|
|
- var _tsconfigUri = 'guide/typescript-configuration.html#tsconfig'
|
|
|
|
|
- var _typingsUri = 'guide/typescript-configuration.html#!#typings'
|
|
|
|
|
|
|
|
|
|
p Add the following package definition and configuration files to the project folder:
|
2016-05-19 04:32:43 -04:00
|
|
|
|
p 往项目目录下添加下列包定义与配置文件:
|
2016-05-14 20:40:52 -04:00
|
|
|
|
ul
|
|
|
|
|
li.
|
2016-05-16 20:10:19 -04:00
|
|
|
|
#[b package.json] lists packages the QuickStart app depends on and
|
2016-05-14 20:40:52 -04:00
|
|
|
|
defines some useful scripts.
|
|
|
|
|
See #[a(href="guide/npm-packages.html") Npm Package Configuration] for details.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
li.
|
|
|
|
|
#[b package.json] 列出了“快速起步”应用的依赖,并定义了一些有用的脚本。
|
2016-05-19 05:03:55 -04:00
|
|
|
|
参见#[a(href="guide/npm-packages.html") npm包配置]了解详情。
|
2016-05-14 20:40:52 -04:00
|
|
|
|
li.
|
|
|
|
|
#[b tsconfig.json] is the TypeScript compiler configuration file.
|
|
|
|
|
See #[a(href="#{_tsconfigUri}") TypeScript Configuration] for details.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
li.
|
|
|
|
|
#[b tsconfig.json]是TypeScript的编译器配置文件。
|
|
|
|
|
参见#[a(href="#{_tsconfigUri}") TypeScript配置]了解详情。
|
2016-05-14 20:40:52 -04:00
|
|
|
|
li.
|
|
|
|
|
#[b typings.json] identifies TypeScript definition files.
|
|
|
|
|
See #[a(href="#{_typingsUri}") TypeScript Configuration] for details.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
li.
|
|
|
|
|
#[b typings.json]指定TypeScript定义文件。
|
|
|
|
|
参见#[a(href="#{_typingsUri}") TypeScript定义文件]了解详情
|
2016-05-14 20:40:52 -04:00
|
|
|
|
li.
|
|
|
|
|
#[b systemjs.config.js], the SystemJS configuration file.
|
|
|
|
|
See discussion #[a(href="#systemjs") below].
|
2016-05-19 04:32:43 -04:00
|
|
|
|
li.
|
|
|
|
|
#[b systemjs.config.js]是SystemJS的配置文件。
|
|
|
|
|
参见#[a(href="#systemjs") 下面的讨论]。
|
2016-05-16 20:10:19 -04:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
a#config-files
|
|
|
|
|
+makeTabs(`
|
|
|
|
|
quickstart/ts/package.1.json,
|
|
|
|
|
quickstart/ts/tsconfig.1.json,
|
|
|
|
|
quickstart/ts/typings.1.json,
|
|
|
|
|
quickstart/ts/systemjs.config.1.js
|
|
|
|
|
`, '', `
|
|
|
|
|
package.json,
|
|
|
|
|
tsconfig.json,
|
|
|
|
|
typings.json,
|
|
|
|
|
systemjs.config.js
|
|
|
|
|
`)
|
|
|
|
|
|
2016-05-19 05:21:12 -04:00
|
|
|
|
h3#install-packages (c) #{_Install} packages
|
|
|
|
|
h3#install-packages (c) #{_InstallCn}依赖包
|
2016-05-14 20:40:52 -04:00
|
|
|
|
block install-packages
|
2016-02-12 20:54:22 -05:00
|
|
|
|
:marked
|
2016-05-16 20:10:19 -04:00
|
|
|
|
We install the packages listed in `package.json` using `npm`. Enter the
|
2016-05-14 20:40:52 -04:00
|
|
|
|
following command in a terminal window (command window in Windows):
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
我们使用`npm`命令来安装`package.json`中列出的依赖包。请在终端窗口(或Windows的cmd窗口)中输入下列命令:
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
code-example(language="sh").
|
|
|
|
|
npm install
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
.alert.is-important
|
|
|
|
|
:marked
|
2016-05-16 20:10:19 -04:00
|
|
|
|
Scary <span style="color:red; font-weight: bold">error messages in red</span> may appear **during** install.
|
2016-05-14 20:40:52 -04:00
|
|
|
|
The install typically recovers from these errors and finishes successfully.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
在安装期间,可能会出现恐怖的<span style="color:red; font-weight: bold">红色错误信息</span>。
|
|
|
|
|
别担心,安装通常都能从这些错误中自行恢复,并最终成功。
|
2016-05-14 20:40:52 -04:00
|
|
|
|
.l-verbose-section(class="l-verbose-inherit")
|
|
|
|
|
:marked
|
|
|
|
|
#### npm errors and warnings
|
2016-05-19 04:32:43 -04:00
|
|
|
|
#### npm错误与警告
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-16 20:10:19 -04:00
|
|
|
|
All is well if there are no console messages starting with `npm ERR!` *at the end* of **npm install**.
|
2016-05-14 20:40:52 -04:00
|
|
|
|
There might be a few `npm WARN` messages along the way — and that is perfectly fine.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
只要没在*npm install*的*末尾*出现以`npm ERR!`开头儿的控制台信息,那就没事。
|
|
|
|
|
可能会出现一些`npm WARN`消息,这些都不用管。
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-16 20:10:19 -04:00
|
|
|
|
We often see an `npm WARN` message after a series of `gyp ERR!` messages.
|
|
|
|
|
Ignore them. A package may try to recompile itself using `node-gyp`.
|
|
|
|
|
If the recompile fails, the package recovers (typically with a pre-built version)
|
2016-05-14 20:40:52 -04:00
|
|
|
|
and everything works.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
我们通常会在一系列`gyp ERR!`消息后面看到一个`npm WARN`消息。直接忽略即可。
|
|
|
|
|
有些依赖包可能会尝试用`node-gyp`重新编译它自己。
|
2016-05-19 05:21:12 -04:00
|
|
|
|
如果重新编译失败了,这个包就会自行恢复(通常是下载一个预编译版本),最终不会影响使用。
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
Just make sure there are no `npm ERR!` messages at the end of `npm install`.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
只要确认在`npm install`输出的末尾没有`npm ERR!`消息就行了。
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
.l-verbose-section
|
|
|
|
|
:marked
|
|
|
|
|
#### Adding the libraries and packages we need with *npm*
|
2016-05-19 05:21:12 -04:00
|
|
|
|
#### 用*npm*添加我们需要的库和依赖包
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
Angular application developers rely on the _[npm](https://docs.npmjs.com)_
|
2016-05-16 20:10:19 -04:00
|
|
|
|
package manager to install the libraries and packages their apps require.
|
|
|
|
|
The Angular team recommends the starter-set of packages specified in the
|
2016-05-14 20:40:52 -04:00
|
|
|
|
`dependencies` and `devDependencies` sections.
|
|
|
|
|
See the [npm packages](guide/npm-packages.html) chapter for details.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
2016-05-19 05:21:12 -04:00
|
|
|
|
Angular应用开发者依靠_[npm](https://docs.npmjs.com)_包管理器来安装应用所需的库和依赖包。
|
2016-05-19 04:32:43 -04:00
|
|
|
|
Angular开发组建议的那组初学者包是通过`dependencies`和`devDependencies`指定的。
|
|
|
|
|
要了解详情,参见[npm包](guide/npm-packages.html)一章。
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
#### Helpful scripts
|
2016-05-19 04:32:43 -04:00
|
|
|
|
#### 有用的脚本
|
2016-05-14 20:40:52 -04:00
|
|
|
|
We've included a number of npm scripts in our suggested `package.json` to handle common development tasks:
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
2016-05-19 05:21:12 -04:00
|
|
|
|
在我们推荐的这个`package.json`中,包含了几个npm脚本,用来处理常用的开发任务:
|
2016-05-19 04:32:43 -04:00
|
|
|
|
+makeJson('quickstart/ts/package.1.json',{ paths: 'scripts'}, 'package.json (脚本)')(format=".")
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-02-17 22:31:42 -05:00
|
|
|
|
:marked
|
2016-05-16 20:10:19 -04:00
|
|
|
|
We execute most npm scripts in the following way: `npm run` followed by a *script-name*.
|
2016-05-14 20:40:52 -04:00
|
|
|
|
Some commands (such as `start`) don't require the `run` keyword.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
我们执行大多数npm脚本的方式都差不多:`npm run`后面跟着*脚本名*。
|
|
|
|
|
有些命令(比如`start`)不需要`run`关键字。
|
2016-02-12 20:54:22 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
Here's what these scripts do:
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
这些脚本的用途如下:
|
2016-02-17 22:31:42 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
* `npm start` - runs the compiler and a server at the same time, both in "watch mode"
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
* `npm start` - 同时运行编译器和一个服务器,它们都工作在“监视模式”下。
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
* `npm run tsc` - runs the TypeScript compiler once
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
* `npm run tsc` - 运行一次TypeScript编译器
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-16 20:10:19 -04:00
|
|
|
|
* `npm run tsc:w` - runs the TypeScript compiler in watch mode;
|
|
|
|
|
the process keeps running, awaiting changes to TypeScript files and recompiling when it sees them
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
2016-05-19 05:21:12 -04:00
|
|
|
|
* `npm run tsc:w` - 在“监视模式”下运行TypeScript编译器,进程持续运行,等待TypeScript文件的变化,一旦变化,就重新编译它们。
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-16 20:10:19 -04:00
|
|
|
|
* `npm run lite` - runs the <a href="https://www.npmjs.com/package/lite-server" target="_blank">lite-server</a>,
|
2016-05-14 20:40:52 -04:00
|
|
|
|
a light-weight, static file server with excellent support for Angular apps that use routing
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
* `npm run lite` - 运行<a href="https://www.npmjs.com/package/lite-server" target="_blank">lite-server</a> —— 一个轻量级、静态的文件服务器,对使用路由的Angular应用提供了优秀的支持。
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
* `npm run typings` - runs the [*typings* tool](#{_typingsUri}) separately
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
* `npm run typings` - 单独运行[*typings*工具](#{_typingsUri})
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
* `npm run postinstall` - called by *npm* automatically *after* it successfully completes package installation.
|
|
|
|
|
This script installs the [TypeScript definition files](#{_typingsUri}) defined in `typings.json`
|
2016-02-17 22:31:42 -05:00
|
|
|
|
|
2016-05-19 04:32:43 -04:00
|
|
|
|
* `npm run postinstall` - 当*npm*安装完当前包时,它会被自动调用。这里的这个脚本会安装`typings.json`中定义的[TypeScript定义文件](#{_typingsUri})
|
2015-12-10 21:29:14 -05:00
|
|
|
|
:marked
|
|
|
|
|
**We're all set.** Let's write some code.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
**全部设置完了。** 我们来写点代码吧。
|
2015-08-08 16:55:53 -04:00
|
|
|
|
|
2015-10-14 23:25:19 -04:00
|
|
|
|
.l-main-section
|
2016-05-16 20:10:19 -04:00
|
|
|
|
h2#root-component Step 2: Our first Angular component
|
2016-05-19 04:32:43 -04:00
|
|
|
|
h2#root-component 步骤2:我们的第一个Angular组件
|
2015-12-10 21:29:14 -05:00
|
|
|
|
:marked
|
2016-02-12 20:54:22 -05:00
|
|
|
|
Let's create a folder to hold our application and add a super-simple Angular component.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
我们来创建一个文件夹,用于保存我们的应用,并且添加一个超级简单的Angular组件。
|
2016-02-12 20:54:22 -05:00
|
|
|
|
|
2016-05-16 20:10:19 -04:00
|
|
|
|
**Create #{_an} #{_appDir} subfolder** off the project root directory:
|
2016-05-19 05:21:12 -04:00
|
|
|
|
|
2016-05-19 04:32:43 -04:00
|
|
|
|
在项目的根目录下**创建一个#{_appDir}子目录**:
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
code-example.
|
|
|
|
|
mkdir #{_appDir}
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
a#app-component
|
|
|
|
|
p.
|
2016-05-16 20:10:19 -04:00
|
|
|
|
#[b Create the component file]
|
2016-05-14 20:40:52 -04:00
|
|
|
|
#[code #[+adjExPath('app/app.component.ts')]] (in this newly created directory) with the following content:
|
2016-05-19 04:32:43 -04:00
|
|
|
|
p.
|
|
|
|
|
#[b 创建组件文件]
|
|
|
|
|
#[code #[+adjExPath('app/app.component.ts')]] (在新建的这个目录中),内容如下:
|
2016-02-12 20:54:22 -05:00
|
|
|
|
|
2016-05-18 13:27:51 -04:00
|
|
|
|
+makeProjExample('app/app.component.ts')
|
2016-04-09 09:26:00 -04:00
|
|
|
|
|
2016-02-12 20:54:22 -05:00
|
|
|
|
.l-verbose-section
|
|
|
|
|
:marked
|
|
|
|
|
### AppComponent is the root of the application
|
2016-05-19 04:32:43 -04:00
|
|
|
|
### AppComponent是应用的根目录
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
Every Angular app has at least one **root component**, conventionally named `AppComponent`,
|
2016-02-12 20:54:22 -05:00
|
|
|
|
that hosts the client user experience.
|
|
|
|
|
Components are the basic building blocks of Angular applications.
|
|
|
|
|
A component controls a portion of the screen — a *view* — through its associated template.
|
2015-12-14 18:44:50 -05:00
|
|
|
|
|
2016-05-19 04:32:43 -04:00
|
|
|
|
每个Angular应用都至少有一个**根组件**,习惯上命名为`AppComponent`,它是放用户界面的容器。
|
2016-05-11 03:56:17 -04:00
|
|
|
|
组件是Angular应用程序中最基本的构造块儿。组件通过它所关联的模板,控制屏幕的一部分 —— 这就是 *视图* 。
|
2016-03-07 08:42:10 -05:00
|
|
|
|
|
2016-02-12 20:54:22 -05:00
|
|
|
|
This QuickStart has only one, extremely simple component.
|
|
|
|
|
But it has the essential structure of every component we'll ever write:
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
这个“快速起步”只有一个非常简单的组件,但麻雀虽小,五脏俱全 —— 它具备了我们将来写的组件的基本结构。
|
2016-03-07 08:42:10 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
* One or more [import](#component-import)
|
2016-03-07 08:42:10 -05:00
|
|
|
|
statements to reference the things we need.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
* 一个或多个[import](#component-import)语句来引入我们所需的文件。
|
2016-05-14 20:40:52 -04:00
|
|
|
|
* A [@Component #{_decorator}](#component-decorator)
|
2016-02-12 20:54:22 -05:00
|
|
|
|
that tells Angular what template to use and how to create the component.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
* 一个[@Component #{_decoratorCn}](#component-decorator)
|
|
|
|
|
来告诉Angular,使用哪个模板,以及怎样创建这个组件。
|
2016-05-14 20:40:52 -04:00
|
|
|
|
* A [component class](#component-class)
|
2016-02-12 20:54:22 -05:00
|
|
|
|
that controls the appearance and behavior of a view through its template.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
* 一个[组件类](#component-class)
|
|
|
|
|
来通过它的模板控制一个视图的外观和行为。
|
2016-03-07 08:42:10 -05:00
|
|
|
|
|
2016-05-19 05:21:12 -04:00
|
|
|
|
a#component-import
|
2016-02-12 20:54:22 -05:00
|
|
|
|
:marked
|
|
|
|
|
### Import
|
2016-05-19 04:32:43 -04:00
|
|
|
|
### 导入
|
2015-10-14 23:25:19 -04:00
|
|
|
|
|
2016-02-12 20:54:22 -05:00
|
|
|
|
Angular apps are modular. They consist of many files each dedicated to a purpose.
|
|
|
|
|
Angular itself is modular. It is a collection of library modules
|
|
|
|
|
each made up of several, related features that we'll use to build our application.
|
2016-03-07 08:42:10 -05:00
|
|
|
|
|
2016-05-19 04:32:43 -04:00
|
|
|
|
Angular应用都是模块化的。它们由很多职责明确的文件组成。
|
|
|
|
|
Angular本身也是模块化的。它包括一系列的库模块,这些模块包括了一系列相关的特性,以便我们可以拿来构建自己的应用。
|
|
|
|
|
|
2016-05-16 20:10:19 -04:00
|
|
|
|
When we need something from a module or library, we import it.
|
2016-05-14 20:40:52 -04:00
|
|
|
|
Here we import the Angular 2 core so that our component code can have access to
|
|
|
|
|
the `@Component` #{_decorator}.
|
2016-03-07 08:42:10 -05:00
|
|
|
|
|
2016-05-19 04:32:43 -04:00
|
|
|
|
当我们需要一个模块中的某些东西时,我们引入(import)它。
|
|
|
|
|
在这里,我们导入了Angular 2核心库,以便我们的组件代码能够访问`@Component` #{_decoratorCn}。
|
2016-05-18 13:27:51 -04:00
|
|
|
|
+makeExcerpt('app/app.component.ts', 'import')
|
2016-02-12 20:54:22 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
h3#component-decorator @Component #{_decorator}
|
2016-05-19 04:32:43 -04:00
|
|
|
|
h3#component-decorator @Component #{_decoratorCn}
|
2016-05-14 20:40:52 -04:00
|
|
|
|
+ifDocsFor('ts')
|
|
|
|
|
:marked
|
|
|
|
|
`Component` is a *decorator function* that takes a *metadata object* as argument.
|
2016-05-16 20:10:19 -04:00
|
|
|
|
We apply this function to the component class by prefixing the function with the
|
2016-05-14 20:40:52 -04:00
|
|
|
|
**@** symbol and invoking it with a metadata object, just above the class.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
`Component`是一个*装饰器函数*,它接受一个*元数据对象*作为参数。
|
|
|
|
|
通过给这个函数加上**@**前缀,我们就可以把这个函数加到组件类上,比如上面这个类。
|
2015-11-10 13:31:46 -05:00
|
|
|
|
:marked
|
2016-05-16 20:10:19 -04:00
|
|
|
|
`@Component` is #{_a} *#{_decorator}* that allows us to associate *metadata* with the
|
2016-05-14 20:40:52 -04:00
|
|
|
|
component class.
|
|
|
|
|
The metadata tells Angular how to create and use this component.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
2016-05-19 05:21:12 -04:00
|
|
|
|
`@Component` 是一个*#{_decoratorCn}*,它允许我们把*元数据*关联到组件类上。这些元数据会告诉Angular如何创建和使用我们的类。
|
2016-03-07 08:42:10 -05:00
|
|
|
|
|
2016-05-18 13:27:51 -04:00
|
|
|
|
+makeExcerpt('app/app.component.ts', 'metadata')
|
2016-03-07 08:42:10 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
block annotation-fields
|
|
|
|
|
:marked
|
|
|
|
|
This particular metadata object has two fields, a `selector` and a `template`.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
这里的这个元数据对象有两个字段:一个`selector`,一个`template`。
|
2016-02-12 20:54:22 -05:00
|
|
|
|
:marked
|
|
|
|
|
The **selector** specifies a simple CSS selector for an HTML element that represents the component.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
**selector**字段指定了一个简单的CSS选择器,用于指出放置此组件的HTML元素。
|
2016-03-07 08:42:10 -05:00
|
|
|
|
|
2016-02-12 20:54:22 -05:00
|
|
|
|
>The element for this component is named `my-app`.
|
|
|
|
|
Angular creates and displays an instance of our `AppComponent`
|
|
|
|
|
wherever it encounters a `my-app` element in the host HTML.
|
2015-12-10 21:29:14 -05:00
|
|
|
|
|
2016-03-07 08:42:10 -05:00
|
|
|
|
>在此组件中,这个元素被命名为`my-app`。
|
|
|
|
|
Angular创建和显示`AppComponent`组件的一个实例。
|
|
|
|
|
然后把它放在宿主页面的一个`my-app`元素中。
|
|
|
|
|
|
2016-05-11 03:56:17 -04:00
|
|
|
|
The **template** specifies the component's companion template,
|
|
|
|
|
written in an enhanced form of HTML that tells Angular how to render this component's view.
|
|
|
|
|
|
2016-05-19 04:32:43 -04:00
|
|
|
|
**template**字段指定了此组件的模板。
|
|
|
|
|
它用一种增强的HTML形式写成,用来告诉Angular如何渲染此组件的视图。
|
|
|
|
|
|
2016-05-17 02:16:11 -04:00
|
|
|
|
>Our template is a single line of HTML announcing "*My First Angular 2 App*".
|
2016-03-07 08:42:10 -05:00
|
|
|
|
|
2016-05-19 04:32:43 -04:00
|
|
|
|
>我们的模板中只有一行HTML:“*My First Angular App*”。
|
|
|
|
|
|
2016-02-12 20:54:22 -05:00
|
|
|
|
>A more advanced template could contain data bindings to component properties
|
2016-03-07 08:42:10 -05:00
|
|
|
|
and might identify other application compoents which have their own templates.
|
2016-02-12 20:54:22 -05:00
|
|
|
|
These templates might identify yet other components.
|
|
|
|
|
In this way an Angular application becomes a tree of components.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
>更高级的模板还可以包含到组件属性的数据绑定。还可以包含其它组件,这些组件还可以有自己的模板。
|
|
|
|
|
这些模板中还可以进一步包含其它组件。从这个意义上讲,一个Angular应用就是一棵组件树。
|
2016-02-12 20:54:22 -05:00
|
|
|
|
|
|
|
|
|
:marked
|
|
|
|
|
### Component class
|
2016-03-07 08:42:10 -05:00
|
|
|
|
### Component类
|
2016-02-12 20:54:22 -05:00
|
|
|
|
At the bottom of the file is an empty, do-nothing class named `AppComponent`.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
文件的最底下,是一个空的,什么也不做的类,叫做`AppComponent`。
|
2016-05-18 13:27:51 -04:00
|
|
|
|
+makeExcerpt('app/app.component.ts', 'class')
|
2016-02-12 20:54:22 -05:00
|
|
|
|
:marked
|
2016-05-16 20:10:19 -04:00
|
|
|
|
When we're ready to build a substantive application,
|
|
|
|
|
we can expand this class with properties and application logic.
|
2016-02-12 20:54:22 -05:00
|
|
|
|
Our `AppComponent` class is empty because we don't need it to do anything in this QuickStart.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
当我们打算构建一个真实的应用时,可以通过添加属性和应用逻辑来扩展这个类。
|
|
|
|
|
但我们不需要在这个“快速起步”中做这些事,所以这里的`AppComponent`类是空的。
|
2016-05-14 20:40:52 -04:00
|
|
|
|
+ifDocsFor('ts')
|
|
|
|
|
:marked
|
|
|
|
|
We **export** `AppComponent` so that we can **import** it elsewhere in our application,
|
|
|
|
|
as we'll see when we create `main.ts`.
|
2016-03-07 08:42:10 -05:00
|
|
|
|
|
2016-05-19 04:32:43 -04:00
|
|
|
|
我们**导出**`AppComponent`,以便我们可以在应用的其它地方**导入**它 —— 比如我们创建`main.ts`时。
|
2016-02-12 20:54:22 -05:00
|
|
|
|
.l-main-section
|
2016-05-16 20:10:19 -04:00
|
|
|
|
h2#main Step 3: Add #[code #[+adjExPath('main.ts')]]
|
2016-05-19 04:32:43 -04:00
|
|
|
|
h2#main 步骤3:添加#[code #[+adjExPath('main.ts')]]
|
2016-03-07 08:42:10 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
block create-main
|
|
|
|
|
p.
|
|
|
|
|
Now we need something to tell Angular to load the root component.
|
|
|
|
|
Create the file #[code #[+adjExPath('app/main.ts')]] with the following content:
|
2016-05-19 04:32:43 -04:00
|
|
|
|
p.
|
|
|
|
|
现在,我们还需要做点什么来让Angular加载这个根组件。
|
|
|
|
|
添加一个新文件#[code #[+adjExPath('app/main.ts')]],内容如下:
|
2016-05-18 13:27:51 -04:00
|
|
|
|
+makeProjExample('app/main.ts')
|
2016-02-10 17:58:05 -05:00
|
|
|
|
|
2016-02-12 20:54:22 -05:00
|
|
|
|
.l-verbose-section
|
2015-12-10 21:29:14 -05:00
|
|
|
|
:marked
|
2016-02-12 20:54:22 -05:00
|
|
|
|
We import the two things we need to launch the application:
|
2015-08-08 16:55:53 -04:00
|
|
|
|
|
2016-05-11 03:56:17 -04:00
|
|
|
|
我们引入了两样东西来启动本应用:
|
2016-03-07 08:42:10 -05:00
|
|
|
|
|
2016-02-12 20:54:22 -05:00
|
|
|
|
1. Angular's browser `bootstrap` function
|
2016-05-11 03:56:17 -04:00
|
|
|
|
1. Angular的浏览器`bootstrap`(引导)函数
|
2016-02-12 20:54:22 -05:00
|
|
|
|
1. The application root component, `AppComponent`.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
1. 应用的根组件:`AppComponent`。
|
2016-05-16 20:10:19 -04:00
|
|
|
|
|
2016-02-12 20:54:22 -05:00
|
|
|
|
Then we call `bootstrap` with `AppComponent`.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
然后,我们调用`bootstrap`函数,并且把`AppComponent`传进去。
|
2016-03-07 08:42:10 -05:00
|
|
|
|
|
2016-02-12 20:54:22 -05:00
|
|
|
|
### Bootstrapping is platform-specific
|
2016-05-19 04:32:43 -04:00
|
|
|
|
### “启动”是平台相关的
|
2016-05-14 20:40:52 -04:00
|
|
|
|
Notice that we import the `bootstrap` function from `#{_angular_browser_uri}`,
|
|
|
|
|
not `#{_angular_core_uri}`.
|
2016-02-12 20:54:22 -05:00
|
|
|
|
Bootstrapping isn't core because there isn't a single way to bootstrap the app.
|
|
|
|
|
True, most applications that run in a browser call the bootstrap function from
|
|
|
|
|
this library.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
注意,我们是从`#{_angular_browser_uri}`中引入的`bootstrap`函数,而不是从`#{_angular_core_uri}`中。
|
|
|
|
|
“引导”不是核心的一部分,因为没有单一的途径来启动应用。诚然,大部分应用都是在浏览器中调用`bootstrap`函数的。
|
2016-03-07 08:42:10 -05:00
|
|
|
|
|
|
|
|
|
But it is possible to load a component in a different environment.
|
2016-02-12 20:54:22 -05:00
|
|
|
|
We might load it on a mobile device with [Apache Cordova](https://cordova.apache.org/) or [NativeScript](https://www.nativescript.org/).
|
|
|
|
|
We might wish to render the first page of our application on the server
|
2016-05-16 20:10:19 -04:00
|
|
|
|
to improve launch performance or facilitate
|
2016-03-16 23:04:42 -04:00
|
|
|
|
[SEO](http://www.google.com/webmasters/docs/search-engine-optimization-starter-guide.pdf).
|
2016-02-12 20:54:22 -05:00
|
|
|
|
These targets require a different kind of bootstrap function that we'd import from a different library.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
但从其它环境中加载组件也是可能的。
|
|
|
|
|
我们可能通过[Apache Cordova](https://cordova.apache.org/) 或 [NativeScript](https://www.nativescript.org/) 在移动设备中加载它。
|
|
|
|
|
我们可能希望在服务器中渲染我们的第一个页面来提高启动效率或
|
|
|
|
|
让[SEO](http://static.googleusercontent.com/media/www.google.com/en//webmasters/docs/search-engine-optimization-starter-guide.pdf)更加容易。
|
|
|
|
|
要达成这些目标,我们需要从其它库中引入一个不同类型的`bootstrap`函数。
|
2016-03-07 08:42:10 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
### Why create separate *main.#{_docsFor}* and app component files?
|
2016-05-19 04:32:43 -04:00
|
|
|
|
### 为什么创建一个分离的*main.#{_docsFor}*文件和应用组件文件?
|
2016-03-07 08:42:10 -05:00
|
|
|
|
|
2016-05-16 20:10:19 -04:00
|
|
|
|
Both `main.#{_docsFor}` and the app component files are tiny.
|
2016-05-14 20:40:52 -04:00
|
|
|
|
This is just a QuickStart.
|
|
|
|
|
We could have merged these two files into one
|
2016-02-12 20:54:22 -05:00
|
|
|
|
and spared ourselves some complexity.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
无论是`main.#{_docsFor}`还是组件的文件都非常小。
|
|
|
|
|
它只是一个“快速起步”而已。
|
|
|
|
|
我们本可以把这两个文件装进`app.component`文件来减少一点复杂度。
|
2016-03-07 08:42:10 -05:00
|
|
|
|
|
2016-02-12 20:54:22 -05:00
|
|
|
|
We'd rather demonstrate the proper way to structure an Angular application.
|
2016-05-16 20:10:19 -04:00
|
|
|
|
App bootstrapping is a separate concern from presenting a view.
|
2016-02-12 20:54:22 -05:00
|
|
|
|
Mixing concerns creates difficulties down the road.
|
2016-05-16 20:10:19 -04:00
|
|
|
|
We might launch the `AppComponent` in multiple environments with different bootstrappers.
|
2016-02-12 20:54:22 -05:00
|
|
|
|
Testing the component is much easier if it doesn't also try to run the entire application.
|
|
|
|
|
Let's make the small extra effort to do it *the right way*.
|
2016-04-09 09:26:00 -04:00
|
|
|
|
|
2016-05-11 03:56:17 -04:00
|
|
|
|
但我们应该用正确的方式组织Angular应用的文件结构。
|
2016-04-09 09:26:00 -04:00
|
|
|
|
启动App与展现视图是两个相互分离的关注点。
|
|
|
|
|
把这些关注点混在一起会增加不必要的难度。
|
2016-05-11 03:56:17 -04:00
|
|
|
|
我们可以通过使用不同的引导器(bootstraper)来在不同的环境中启动`AppComponent`。
|
2016-04-09 09:26:00 -04:00
|
|
|
|
测试组件也变得更容易,因为不需要再运行整个程序才能跑测试。
|
|
|
|
|
让我们多花一点精力来用*“正确的方式”*实现它。
|
2016-02-12 20:54:22 -05:00
|
|
|
|
|
2015-08-08 16:55:53 -04:00
|
|
|
|
.l-main-section
|
2016-05-16 20:10:19 -04:00
|
|
|
|
h2#index Step 4: Add #[code index.html]
|
2016-05-19 04:32:43 -04:00
|
|
|
|
h2#index 步骤4:添加#[code index.html]
|
2015-12-10 21:29:14 -05:00
|
|
|
|
:marked
|
2016-05-16 20:10:19 -04:00
|
|
|
|
In the *#{_indexHtmlDir}* folder
|
|
|
|
|
create an `index.html` file and paste the following lines into it:
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
2016-05-19 05:21:12 -04:00
|
|
|
|
在*#{_indexHtmlDirCn}*目录下创建一个`index.html`文件,并粘贴下列内容:
|
2016-04-09 09:26:00 -04:00
|
|
|
|
|
2016-05-18 13:27:51 -04:00
|
|
|
|
+makeProjExample('index.html')
|
2016-04-09 09:26:00 -04:00
|
|
|
|
|
2016-02-12 20:54:22 -05:00
|
|
|
|
.l-verbose-section
|
|
|
|
|
:marked
|
2016-05-16 20:10:19 -04:00
|
|
|
|
The `index.html` file defines the web page that hosts the application.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
`index.html`是存放本应用的宿主页面。
|
2015-08-08 16:55:53 -04:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
block index-html-commentary-for-ts
|
|
|
|
|
:marked
|
|
|
|
|
The noteworthy sections of HTML are:
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
这段儿HTML值得注意的有:
|
2016-04-09 09:26:00 -04:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
1. The JavaScript [libraries](#libraries)
|
2016-05-19 04:32:43 -04:00
|
|
|
|
1. JavaScript [库](#libraries)
|
2016-05-14 20:40:52 -04:00
|
|
|
|
2. Configuration file for [SystemJS](#systemjs), and a script
|
|
|
|
|
where we import and run the `app` module which refers to the `main` file that we just wrote.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
2. 配置[SystemJS](#systemjs),以便引入和运行我们刚才写的`main`文件。
|
2016-05-14 20:40:52 -04:00
|
|
|
|
3. The [`<my-app>`](#my-app) tag in the `<body>` which is *where our app lives!*
|
2016-05-19 04:32:43 -04:00
|
|
|
|
3. `<body>`中的[<my-app>](#my-app)标签是*供我们的应用“生活”的地方。*
|
2016-04-09 09:26:00 -04:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
:marked
|
|
|
|
|
### Libraries
|
2016-05-19 04:32:43 -04:00
|
|
|
|
### 库
|
2016-05-14 20:40:52 -04:00
|
|
|
|
We loaded the following scripts
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
我们加载下列脚本:
|
2016-05-18 13:27:51 -04:00
|
|
|
|
+makeExcerpt('index.html', 'libraries')
|
2016-05-14 20:40:52 -04:00
|
|
|
|
:marked
|
2016-05-20 02:18:18 -04:00
|
|
|
|
We begin with `core-js`'s ES2015/ES6 shim which monkey patches the global context (window) with essential features of ES2015 (ES6).
|
2016-05-14 20:40:52 -04:00
|
|
|
|
Next are the polyfills for Angular2, `zone.js` and `reflect-metadata`.
|
|
|
|
|
Then the [SystemJS](#systemjs) library for module loading.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
我们首先引入es6-shim,它会给全局对象window打上补丁,使其支持ES2015(ES6)的必备特性。
|
|
|
|
|
然后是Angular 2的polyfills,以及`zone.js`和`reflect-metadata`。
|
|
|
|
|
然后是用于模块加载的[SystemJS](#systemjs)库。
|
2015-08-08 16:55:53 -04:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
We'll make different choices as we gain experience and
|
|
|
|
|
become more concerned about production qualities such as
|
|
|
|
|
load times and memory footprint.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
等我们变得更有经验、更关心产品质量(如加载时间、内存足迹等),也可以做出不同的选择。
|
2016-05-14 20:40:52 -04:00
|
|
|
|
h3#systemjs SystemJS
|
2016-05-03 11:43:03 -04:00
|
|
|
|
:marked
|
2016-05-14 20:40:52 -04:00
|
|
|
|
QuickStart uses <a href="https://github.com/systemjs/systemjs" target="_blank">SystemJS</a>
|
|
|
|
|
to load application and library modules. [Earlier](#add-config-files) we
|
|
|
|
|
added the `systemjs.config.js` file to the project root.
|
|
|
|
|
There are alternatives that work just fine including the well-regarded
|
|
|
|
|
[webpack](guide/webpack.html).
|
2016-05-16 20:10:19 -04:00
|
|
|
|
SystemJS happens to be a good choice.
|
2016-05-14 20:40:52 -04:00
|
|
|
|
But we want to be clear that it was a *choice* and not a *preference*.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
本“快速起步”使用<a href="https://github.com/systemjs/systemjs" target="_blank">SystemJS</a>来加载应用和库模块。
|
|
|
|
|
[以前](#add-config-files)我们曾把`systemjs.config.js`文件添加到项目的根目录。
|
|
|
|
|
还有一些其它候选者也能很好地工作,比如备受推崇的[webpack](guide/webpack.html)。
|
|
|
|
|
SystemJS是一个好的选择,但要清楚,它只是我们给你的“选择之一”,而不是“首选项”。
|
2016-05-14 20:40:52 -04:00
|
|
|
|
|
2016-05-16 20:10:19 -04:00
|
|
|
|
All module loaders require configuration and all loader configuration
|
2016-05-14 20:40:52 -04:00
|
|
|
|
becomes complicated rather quickly as soon as the file structure diversifies and
|
|
|
|
|
we start thinking about building for production and performance.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
所有loader(模块加载器)都需要配置,并且文件结构很快就会变得多样,
|
|
|
|
|
loader的配置也会变得复杂,那时候我们就要开始考虑产品构建和性能问题了。
|
2016-05-14 20:40:52 -04:00
|
|
|
|
|
|
|
|
|
We suggest becoming well-versed in the loader of your choice.
|
|
|
|
|
Learn more about SystemJS configuration
|
|
|
|
|
<a href="https://github.com/systemjs/systemjs/blob/master/docs/config-api.md" target="_blank">here</a>.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
我们建议你要精通你所选的loader。
|
|
|
|
|
要学习如何配置SystemJS的更多知识,参见<a href="https://github.com/systemjs/systemjs/blob/master/docs/config-api.md" target="_blank">这里</a>。
|
2016-05-14 20:40:52 -04:00
|
|
|
|
|
2016-05-16 20:10:19 -04:00
|
|
|
|
With those cautions in mind, what are we doing in the
|
2016-05-14 20:40:52 -04:00
|
|
|
|
QuickStart [`systemjs.config.js` configuration file we added earlier](#config-files)?
|
|
|
|
|
First, we create a map to tell SystemJS where to look when we import some module.
|
2016-05-16 20:10:19 -04:00
|
|
|
|
Then, we register all our packages to SystemJS:
|
2016-05-14 20:40:52 -04:00
|
|
|
|
all the project dependencies and our application package, `app`.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
把这些记在心里,我们再来看看加在“快速起步”中的[`systemjs.config.js`配置文件](#config-files)都做了什么。
|
|
|
|
|
首先,创建了一个映射表,来告诉SystemJS当想要引入某些模块的时候,该到哪里去找。
|
|
|
|
|
然后,我们把自己的所有包注册到SystemJS中:
|
|
|
|
|
项目的所有外部依赖,以及我们自己的应用包`app`。
|
2016-05-14 20:40:52 -04:00
|
|
|
|
|
|
|
|
|
.l-sub-section
|
|
|
|
|
:marked
|
2016-05-16 20:10:19 -04:00
|
|
|
|
Our QuickStart doesn't use all of the listed packages
|
2016-05-14 20:40:52 -04:00
|
|
|
|
but any substantial application will want many of them
|
|
|
|
|
and all of the listed packages are required by at least one of the documentation samples.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
这份“快速起步”不会用到这里列出的所有依赖包,但是大量应用都会用到它们,而且本文档的范例中至少有一个用到了这里列出的所有依赖包。
|
2016-05-14 20:40:52 -04:00
|
|
|
|
|
|
|
|
|
There is no runtime harm in listing packages that we don't need as they will only be loaded when requested.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
列出那些不需要的包也不会损害应用的运行期表现,因为只有被实际用到的包才会被加载。
|
2016-02-12 20:54:22 -05:00
|
|
|
|
:marked
|
2016-05-16 20:10:19 -04:00
|
|
|
|
The `app` package tells SystemJS what to do when it sees a request for a
|
|
|
|
|
module from the `app/` folder.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
`app`包告诉SystemJS,当有人请求`app/`目录下的某个模块时,它应该怎么做。
|
2016-04-09 09:26:00 -04:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
Our QuickStart makes such requests when one of its
|
|
|
|
|
application TypeScript files has an import statement like this:
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
在我们的“快速起步”中,当应用中的一个TypeScript文件有这样的一个导入语句时:
|
2016-05-18 13:27:51 -04:00
|
|
|
|
+makeExcerpt('app/main.ts', 'import')
|
2016-05-19 04:32:43 -04:00
|
|
|
|
:marked
|
|
|
|
|
SystemJS就会开始介入。
|
2016-02-12 20:54:22 -05:00
|
|
|
|
:marked
|
2016-05-16 20:10:19 -04:00
|
|
|
|
Notice that the module name (after `from`) does not mention a filename extension.
|
2016-05-14 20:40:52 -04:00
|
|
|
|
In the configuration we tell SystemJS to default the extension to `js`, a JavaScript file.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
注意,模块名(`from`后面)并不包含文件的扩展名。
|
|
|
|
|
`package:`配置项告诉SystemJS使用'js'扩展名,也就是加载一个JavaScript文件。
|
2016-02-12 20:54:22 -05:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
That makes sense because we transpile TypeScript to JavaScript
|
|
|
|
|
*before* running the application.
|
2016-02-12 20:54:22 -05:00
|
|
|
|
|
2016-05-19 04:32:43 -04:00
|
|
|
|
这是因为我们在运行应用程序*之前*会执行从TypeScript到JavaScript的转译(transpile)。
|
2016-05-14 20:40:52 -04:00
|
|
|
|
.l-sub-section
|
|
|
|
|
:marked
|
|
|
|
|
#### Transpiling in the browser
|
2016-05-19 04:32:43 -04:00
|
|
|
|
#### 在浏览器中转译
|
2016-05-14 20:40:52 -04:00
|
|
|
|
In the live example on plunker we transpile (AKA compile) to JavaScript in the browser
|
2016-05-16 20:10:19 -04:00
|
|
|
|
on the fly. _That's fine for a demo_.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
在plunker上的在线例子中,我们在浏览器中随时转译(也可以叫编译)到JavaScript。对于演示来说,这足够了。
|
2016-04-09 09:26:00 -04:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
**Do not transpile in the browser during development or for production**.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
**但不要开发环境或产品环境中使用浏览器中转译的方式**。
|
2016-04-09 09:26:00 -04:00
|
|
|
|
|
2016-05-16 20:10:19 -04:00
|
|
|
|
We strongly recommend transpiling (AKA compiling) to JavaScript during a build phase
|
2016-05-14 20:40:52 -04:00
|
|
|
|
before running the application for several reasons including:
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
我们强烈建议在运行应用之前的build阶段转译(编译)到JavaScript,理由包括:
|
2016-05-14 20:40:52 -04:00
|
|
|
|
|
|
|
|
|
* We see compiler warnings and errors that are hidden from us in the browser.
|
|
|
|
|
|
2016-05-19 04:32:43 -04:00
|
|
|
|
* 我们可以看到编译器的警告和错误,但浏览器中不行。
|
|
|
|
|
|
2016-05-25 07:17:02 -04:00
|
|
|
|
* Precompilation simplifies the module loading process and
|
2016-05-14 20:40:52 -04:00
|
|
|
|
it's much easier to diagnose problems when this is a separate, external step.
|
|
|
|
|
|
2016-05-19 04:32:43 -04:00
|
|
|
|
* 预编译简化了模块加载过程,而且当它成为分离、外部的步骤时,更容易诊断问题。
|
|
|
|
|
|
2016-05-16 20:10:19 -04:00
|
|
|
|
* Precompilation means a faster user experience because the browser doesn't waste time compiling.
|
2016-05-14 20:40:52 -04:00
|
|
|
|
|
2016-05-19 04:32:43 -04:00
|
|
|
|
* 预编译意味着更快的用户体验,因为浏览器不用浪费时间去编译了。
|
|
|
|
|
|
2016-05-16 20:10:19 -04:00
|
|
|
|
* We iterate development faster because we only recompile changed files.
|
2016-05-14 20:40:52 -04:00
|
|
|
|
We notice the difference as soon as the app grows beyond a handful of files.
|
|
|
|
|
|
2016-05-19 04:32:43 -04:00
|
|
|
|
* 我们的迭代开发会更快,因为我们只需要重新编译那些有变化的文件。当应用程序快速膨胀成一大堆文件时,你会体验到这些差异。
|
|
|
|
|
|
2016-05-16 20:10:19 -04:00
|
|
|
|
* Precompilation fits into a continuous integration process of build, test, deploy.
|
2016-04-09 09:26:00 -04:00
|
|
|
|
|
2016-05-19 04:32:43 -04:00
|
|
|
|
* 预编译更适应CI(持续集成)过程:构建、测试、部署。
|
|
|
|
|
|
2016-02-12 20:54:22 -05:00
|
|
|
|
:marked
|
2016-05-16 20:10:19 -04:00
|
|
|
|
The `System.import` call tells SystemJS to import the `main` file
|
2016-05-14 20:40:52 -04:00
|
|
|
|
(`main.js` ... after transpiling `main.ts`, remember?);
|
|
|
|
|
`main` is where we tell Angular to launch the application.
|
2016-05-16 20:10:19 -04:00
|
|
|
|
We also catch and log launch errors to the console.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
`System.import`调用告诉SystemJS引入`main`文件。(`main.js`,从`main.ts`转译而来的,还记得吧?)
|
|
|
|
|
`main`是我们让Angular启动应用的地方。
|
|
|
|
|
我们还会把启动过程中的错误捕获并记录到控制台中。
|
2016-04-09 09:26:00 -04:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
All other modules are loaded upon request
|
|
|
|
|
either by an import statement or by Angular itself.
|
|
|
|
|
|
2016-05-19 04:32:43 -04:00
|
|
|
|
在接下来的请求中,所有其它模块都会被加载 —— 不管是被import语句还是Angular自身。
|
|
|
|
|
|
2016-05-16 20:10:19 -04:00
|
|
|
|
### *<my-app>*
|
2016-04-09 09:26:00 -04:00
|
|
|
|
|
2016-02-12 20:54:22 -05:00
|
|
|
|
a(id="my-app")
|
|
|
|
|
:marked
|
2016-05-14 20:40:52 -04:00
|
|
|
|
When Angular calls the `bootstrap` function in `main.#{_docsFor}`, it reads the `AppComponent`
|
2016-02-12 20:54:22 -05:00
|
|
|
|
metadata, finds the `my-app` selector, locates an element tag named `my-app`,
|
2016-05-14 20:40:52 -04:00
|
|
|
|
and renders our application's view between those tags.
|
2015-08-08 16:55:53 -04:00
|
|
|
|
|
2016-05-19 04:32:43 -04:00
|
|
|
|
当Angular在`main.ts`中调用`bootstrap`函数时,它读取`AppComponent`的元数据,
|
|
|
|
|
发现选择器是`my-app`,于是它定位到一个元素名为`my-app`的DOM元素,并且把我们的应用加载到这个标签中。
|
2016-03-13 15:50:50 -04:00
|
|
|
|
:marked
|
2016-05-14 20:40:52 -04:00
|
|
|
|
### Add some style
|
2016-05-19 04:32:43 -04:00
|
|
|
|
### 添加一些样式
|
2016-05-16 20:10:19 -04:00
|
|
|
|
Styles aren't essential but they're nice, and `index.html` assumes we have
|
2016-03-13 15:50:50 -04:00
|
|
|
|
a stylesheet called `styles.css`.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
样式不是必备的,但是它让我们的应用更漂亮。`index.html`假设我们有一个名叫`styles.css`的样式表。
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2016-05-16 20:10:19 -04:00
|
|
|
|
Create a `styles.css` file in the *#{_indexHtmlDir}* folder and start styling, perhaps with the minimal
|
|
|
|
|
styles shown below. For the full set of master styles used by the documentation samples,
|
|
|
|
|
see [styles.css](https://github.com/angular/angular.io/blob/master/public/docs/_examples/styles.css).
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
2016-05-19 05:21:12 -04:00
|
|
|
|
在*#{_indexHtmlDirCn}*目录下创建一个`styles.css`文件来加上样式,可能是像下面这样的最小化版本。
|
2016-05-19 04:32:43 -04:00
|
|
|
|
要查看本文档中所用到的主样式表的完整集合,参见
|
|
|
|
|
[styles.css](https://github.com/angular/angular.io/blob/master/public/docs/_examples/styles.css)
|
2016-05-18 13:27:51 -04:00
|
|
|
|
+makeExcerpt('styles.1.css')
|
2016-03-03 11:02:33 -05:00
|
|
|
|
|
2015-10-14 23:25:19 -04:00
|
|
|
|
.l-main-section
|
2016-05-16 20:10:19 -04:00
|
|
|
|
h2#build-and-run Step 5: Build and run the app!
|
2016-05-19 04:32:43 -04:00
|
|
|
|
h2#build-and-run 步骤5:构建并运行本应用!
|
2016-05-14 20:40:52 -04:00
|
|
|
|
block run-app
|
|
|
|
|
:marked
|
|
|
|
|
Open a terminal window and enter this command:
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
打开终端窗口,并输入如下命令:
|
2016-05-14 20:40:52 -04:00
|
|
|
|
code-example.
|
|
|
|
|
npm start
|
|
|
|
|
:marked
|
|
|
|
|
That command runs two parallel node processes
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
这个命令运行两个并行的node进程
|
2016-05-14 20:40:52 -04:00
|
|
|
|
1. The TypeScript compiler in watch mode
|
2016-05-19 04:32:43 -04:00
|
|
|
|
1. TypeScript编译器,运行在监视(watch)模式
|
2016-05-14 20:40:52 -04:00
|
|
|
|
1. A static server called **lite-server** that loads `index.html` in a browser
|
|
|
|
|
and refreshes the browser when application files change
|
2016-05-19 04:32:43 -04:00
|
|
|
|
1. 一个名叫 **lite-server** 的静态服务器,它把`index.html`加载到浏览器中
|
|
|
|
|
这样,当应用的文件发生变化时,它会自动刷新浏览器。
|
|
|
|
|
|
2015-10-14 23:25:19 -04:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
In a few moments, a browser tab should open and display
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
稍后,一个浏览器页标签就会打开并显示出来。
|
2016-04-20 08:07:39 -04:00
|
|
|
|
|
2015-12-10 21:29:14 -05:00
|
|
|
|
figure.image-display
|
2016-05-16 20:10:19 -04:00
|
|
|
|
img(src='/resources/images/devguide/quickstart/my-first-app.png' alt="Output of QuickStart app")
|
2016-04-09 09:26:00 -04:00
|
|
|
|
|
2015-12-10 21:29:14 -05:00
|
|
|
|
:marked
|
2016-05-14 20:40:52 -04:00
|
|
|
|
**Great job!**
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
**干得好!**
|
2015-10-14 23:25:19 -04:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
block build-app
|
|
|
|
|
//- Nothing for ts.
|
2015-10-14 23:25:19 -04:00
|
|
|
|
|
2015-12-10 21:29:14 -05:00
|
|
|
|
:marked
|
2016-05-14 20:40:52 -04:00
|
|
|
|
## Make some changes
|
2016-05-19 04:32:43 -04:00
|
|
|
|
### 做点改变
|
2015-08-08 16:55:53 -04:00
|
|
|
|
|
2015-12-10 21:29:14 -05:00
|
|
|
|
Try changing the message to "My SECOND Angular 2 app".
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
试着把消息内容改成“我的第二个Angular2应用”。
|
2016-05-16 20:10:19 -04:00
|
|
|
|
block server-watching
|
2016-05-14 20:40:52 -04:00
|
|
|
|
:marked
|
|
|
|
|
The TypeScript compiler and `lite-server` are watching.
|
|
|
|
|
They should detect the change, recompile the TypeScript into JavaScript,
|
|
|
|
|
refresh the browser, and display the revised message.
|
|
|
|
|
It's a nifty way to develop an application!
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
TypeScript编译器和`lite-server`都在监视。
|
|
|
|
|
它们会检测到文件的变化,重新把这个TypeScript文件编译成JavaScript文件,刷新浏览器,并且显示修改过的消息。
|
|
|
|
|
这就是我们开发应用程序的方式,多漂亮!
|
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
We close the terminal window when we're done to terminate both the compiler and the server.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
当终止了编译器和服务器之后,我们可以关闭terminal窗口。
|
2015-10-14 23:25:19 -04:00
|
|
|
|
.l-main-section
|
2015-12-10 21:29:14 -05:00
|
|
|
|
:marked
|
2016-05-14 20:40:52 -04:00
|
|
|
|
# Wrap up
|
2016-05-19 04:32:43 -04:00
|
|
|
|
# 完工!
|
2016-04-09 09:26:00 -04:00
|
|
|
|
|
2015-12-10 21:29:14 -05:00
|
|
|
|
Our final project folder structure looks like this:
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
最终的项目目录结构是这样的:
|
2016-05-14 20:40:52 -04:00
|
|
|
|
block project-file-structure
|
|
|
|
|
.filetree
|
|
|
|
|
.file angular2-quickstart
|
2016-05-03 01:09:54 -04:00
|
|
|
|
.children
|
2016-05-14 20:40:52 -04:00
|
|
|
|
.file app
|
|
|
|
|
.children
|
|
|
|
|
.file app.component.ts
|
|
|
|
|
.file main.ts
|
|
|
|
|
.file node_modules ...
|
|
|
|
|
.file typings ...
|
|
|
|
|
.file index.html
|
|
|
|
|
.file package.json
|
|
|
|
|
.file styles.css
|
|
|
|
|
.file systemjs.config.js
|
|
|
|
|
.file tsconfig.json
|
|
|
|
|
.file typings.json
|
2015-12-10 21:29:14 -05:00
|
|
|
|
:marked
|
2016-05-16 20:10:19 -04:00
|
|
|
|
Here are the file contents:
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
这里是这些文件的内容:
|
2016-05-05 17:26:31 -04:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
block project-files
|
|
|
|
|
+makeTabs(`
|
|
|
|
|
quickstart/ts/app/app.component.ts,
|
|
|
|
|
quickstart/ts/app/main.ts,
|
|
|
|
|
quickstart/ts/index.html,
|
|
|
|
|
quickstart/ts/package.1.json,
|
|
|
|
|
quickstart/ts/tsconfig.1.json,
|
|
|
|
|
quickstart/ts/typings.1.json,
|
|
|
|
|
quickstart/ts/styles.1.css,
|
|
|
|
|
quickstart/ts/systemjs.config.1.js`
|
|
|
|
|
,null,
|
2016-05-16 20:10:19 -04:00
|
|
|
|
`app/app.component.ts,
|
|
|
|
|
app/main.ts,
|
2016-05-14 20:40:52 -04:00
|
|
|
|
index.html,
|
2016-05-16 20:10:19 -04:00
|
|
|
|
package.json,
|
|
|
|
|
tsconfig.json,
|
2016-05-14 20:40:52 -04:00
|
|
|
|
typings.json,
|
|
|
|
|
styles.css,
|
|
|
|
|
systemjs.config.js`)
|
2015-08-08 16:55:53 -04:00
|
|
|
|
|
|
|
|
|
.l-main-section
|
2015-12-10 21:29:14 -05:00
|
|
|
|
:marked
|
2016-05-14 20:40:52 -04:00
|
|
|
|
## What next?
|
2016-05-19 04:32:43 -04:00
|
|
|
|
## 下一步做什么?
|
|
|
|
|
|
2015-12-10 21:29:14 -05:00
|
|
|
|
Our first application doesn't do much. It's basically "Hello, World" for Angular 2.
|
2016-04-09 09:26:00 -04:00
|
|
|
|
|
2016-05-11 03:56:17 -04:00
|
|
|
|
我们的第一个应用没做什么,它只是Angular 2的“Hello, World”。
|
2015-10-14 23:25:19 -04:00
|
|
|
|
|
2015-12-10 21:29:14 -05:00
|
|
|
|
We kept it simple in our first pass: we wrote a little Angular component,
|
2016-05-14 20:40:52 -04:00
|
|
|
|
created a simple `index.html`, and launched with a
|
2015-12-10 21:29:14 -05:00
|
|
|
|
static file server. That's about all we'd expect to do for a "Hello, World" app.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
2016-05-19 07:23:01 -04:00
|
|
|
|
我们让自己的Angular 2处女航保持简单:我们写了一个小的Angular组件,添加一些JavaScript库到`index.html`,并且启动一个静态文件服务器。
|
2016-05-19 04:32:43 -04:00
|
|
|
|
这就是我们想通过“Hello, World”应用去表现的一切。
|
2015-08-08 16:55:53 -04:00
|
|
|
|
|
2016-05-14 20:40:52 -04:00
|
|
|
|
**We have greater ambitions!**
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
|
|
|
|
**我们还有更宏伟的目标!**
|
2016-05-14 20:40:52 -04:00
|
|
|
|
block what-next-ts-overhead
|
|
|
|
|
:marked
|
2016-05-16 20:10:19 -04:00
|
|
|
|
The good news is that the overhead of setup is (mostly) behind us.
|
2016-05-14 20:40:52 -04:00
|
|
|
|
We'll probably only touch the `package.json` to update libraries.
|
|
|
|
|
We'll likely open `index.html` only if we need to add a library or some css stylesheets.
|
2016-05-19 04:32:43 -04:00
|
|
|
|
|
2016-05-19 07:23:01 -04:00
|
|
|
|
好消息是:准备阶段(几乎)已经结束了。
|
2016-05-19 04:32:43 -04:00
|
|
|
|
我们将来可能只是修改`package.json`来升级依赖库。
|
|
|
|
|
如果需要添加一些库或一些css样式表,我们可以打开`index.html`。
|
2016-05-14 20:40:52 -04:00
|
|
|
|
:marked
|
2016-05-16 20:10:19 -04:00
|
|
|
|
We're about to take the next step and build a small application that
|
2015-12-10 21:29:14 -05:00
|
|
|
|
demonstrates the great things we can build with Angular 2.
|
2015-08-08 16:55:53 -04:00
|
|
|
|
|
2016-04-09 09:26:00 -04:00
|
|
|
|
我们将要开始下一步:构建一个小型应用,以示范更多有意思的Angular 2特性。
|
|
|
|
|
|
2015-12-10 21:29:14 -05:00
|
|
|
|
Join us on the [Tour of Heroes Tutorial](./tutorial)!
|
2016-04-09 09:26:00 -04:00
|
|
|
|
|
2016-04-17 11:31:22 -04:00
|
|
|
|
来吧,开始我们的[英雄指南](./tutorial)!
|