2016-05-14 17:40:52 -07:00
block includes
include _util-fns
2016-07-03 17:11:17 -07:00
:marked
2016-11-28 16:31:06 -05:00
Angular applications are made up of _components_.
2016-11-26 21:43:16 +00:00
A _component_ is the combination of an HTML template and a component class that controls a portion of the screen. Here is an example of a component that displays a simple string:
2016-11-27 09:37:30 +00:00
2017-02-26 15:04:21 +08:00
Angular 应用是由*组件*组成的。
2016-11-28 09:19:26 +00:00
*组件*由 HTML 模板和组件类组成,组件类控制视图。下面是一个显示简单字符串的组件:
2016-11-22 20:07:16 +08:00
2017-02-02 18:38:17 +00:00
+makeExample('src/app/app.component.ts')(format='.')
2016-07-03 17:11:17 -07:00
2016-12-20 14:16:15 -08:00
block qs-src-online-and-local
.l-sub-section
:marked
2017-02-28 23:31:24 +01:00
Try this **<live-example noDownload>QuickStart example on Plunker</live-example>** without installing anything.
2016-12-20 14:16:15 -08:00
Try it locally with the [***QuickStart seed***](guide/setup.html "Setup for local development with the QuickStart seed")
and prepare for development of a real Angular application.
2017-04-15 15:34:47 +08:00
试试这个**<live-example noDownload>Plunker上的QuickStart范例</live-example>**。
也可以在本地使用[***QuickStart种子工程***](guide/setup.html "Setup for local development with the QuickStart seed")来为开发真实的Angular应用做好准备。
2016-11-27 09:37:30 +00:00
2016-12-15 11:53:45 -08:00
:marked
2017-03-31 01:13:42 +02:00
Every component begins with an `@Component` [decorator](glossary.html#decorator '"decorator" explained')
function that takes a _metadata_ object. The metadata object describes how the HTML template and component class work together.
2016-11-26 21:43:16 +00:00
2016-11-28 09:19:26 +00:00
每个组件都以`@Component`[装饰器](glossary.html#!{_decorator} '"!{_decorator}" explained')<span if-docs="ts">函数</span>开始,它<span if-docs="ts">接受一个_元数据_对象参数。该元素对象</span>描述了 HTML 模板和组件类是如何一起工作的。
2016-11-27 09:37:30 +00:00
2016-11-26 21:43:16 +00:00
The `selector` property tells Angular to display the component inside a custom `<my-app>` tag in the `index.html`.
2016-11-27 09:37:30 +00:00
2016-11-28 09:19:26 +00:00
`selector`属性为 Angular 指定了在`index.html`中的自定义`<my-app>`标签里显示该组件。
2016-11-27 09:37:30 +00:00
2017-02-02 18:38:17 +00:00
+makeExample('src/index.html','my-app','index.html (inside <body>)')(format='.')
2015-12-10 18:29:14 -08:00
:marked
2016-11-26 21:43:16 +00:00
The `template` property defines a message inside an `<h1>` header.
2016-11-28 16:31:06 -05:00
The message starts with "Hello" and ends with `{{name}}`,
2016-11-26 21:43:16 +00:00
which is an Angular [interpolation binding](guide/displaying-data.html) expression.
At runtime, Angular replaces `{{name}}` with the value of the component's `name` property.
2016-11-22 17:44:34 -08:00
Interpolation binding is one of many Angular features you'll discover in this documentation.
2016-11-26 21:43:16 +00:00
2016-11-28 09:19:26 +00:00
`template`属性定义了`<h1>`标题里的一条消息。
该消息以 “Hello” 开始,以 Angular [插值绑定](guide/displaying-data.html)表达式`{{name}}`结束。
2016-11-27 09:37:30 +00:00
在运行时, Angular 用组件的`name`属性值替换`{{name}}`。
插值绑定是 Angular 的特征之一。你将在本文档中探索更多 Angular 的特征。
2016-11-22 20:07:16 +08:00
2017-03-31 01:13:42 +02:00
:marked
In the example, change the component class's `name` property from `'Angular'` to `'World'` and see what happens.
2017-04-15 15:34:47 +08:00
在这个例子中,把组件类的`name`属性从`'Angular'`改为`'World'`,看看会怎么样。
2016-11-30 10:10:12 -08:00
2017-03-31 01:13:42 +02:00
.callout.is-helpful
header A word about TypeScript
2017-04-15 15:34:47 +08:00
header 关于 TypeScript
2017-03-31 01:13:42 +02:00
p.
This example is written in <a href="http://www.typescriptlang.org/" target="_blank" title="TypeScript">TypeScript</a>, a superset of JavaScript. Angular
uses TypeScript because its types make it easy to support developer productivity with tooling. You can also write Angular code in JavaScript; <a href="cookbook/ts-to-js.html">this guide</a> explains how.
2016-11-27 09:37:30 +00:00
2017-04-15 15:34:47 +08:00
p.
本例是用 JavaScript 的一个超集 <a href="http://www.typescriptlang.org/" target="_blank" title="TypeScript">TypeScript</a> 编写的。
Angular 使用 TypeScript 是因为它的类型可以帮助工具提高开发者效率。你也可以用 JavaScript 编写 Angular 代码,参见<a href="cookbook/ts-to-js.html">本指南</a>。
2016-03-04 00:02:33 +08:00
2016-11-26 21:43:16 +00:00
.l-sub-section
2017-03-31 01:13:42 +02:00
:marked
### Next step
2016-11-27 09:37:30 +00:00
2017-04-15 15:34:47 +08:00
### 下一步
2016-11-22 20:07:16 +08:00
2017-03-31 01:13:42 +02:00
Start [**learning Angular**](guide/learning-angular.html "Learning Angular").
2016-11-27 09:37:30 +00:00
2017-04-15 15:34:47 +08:00
开始[**学习 Angular**](guide/learning-angular.html "学习 Angular").
2016-08-09 17:38:25 +01:00