angular-cn/public/docs/ts/latest/quickstart.jade

46 lines
2.2 KiB
Plaintext
Raw Normal View History

block includes
include _util-fns
- var _on_Plunkr = 'on Plunkr';
:marked
2016-11-28 16:31:06 -05:00
Angular applications are made up of _components_.
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:
+makeExample('app/app.component.ts')(format='.')
:marked
You can try this out without installing anything. Open the <live-example>QuickStart example !{_on_Plunkr}</live-example> in another tab
and follow along.
Every component begins with an `@Component` [!{_decorator}](glossary.html#!{_decorator} '"!{_decorator}" explained')
<span if-docs="ts">function</span> that
<span if-docs="ts">takes a _metadata_ object. The metadata object</span> describes how the HTML template and component class work together.
2016-11-28 16:31:06 -05:00
The `selector` property tells Angular to display the component inside a custom `<my-app>` tag in the `index.html`.
+makeExample('index.html','my-app','index.html (inside <body>)')(format='.')
:marked
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}}`,
which is an Angular [interpolation binding](guide/displaying-data.html) expression.
2016-11-28 16:31:06 -05:00
At runtime, Angular replaces `{{name}}` with the value of the component's `name` property.
In the example, change the component class's `name` property from `'Angular'` to `'World'` and see what happens.
2016-11-28 16:31:06 -05:00
Interpolation binding is one of many Angular features you'll discover in this documentation.
+ifDocsFor('ts')
.callout.is-helpful
header A word about TypeScript
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.
.l-sub-section
:marked
### Next step
To learn how to write a real application, your next step is to set up a local development
environment and begin exploring with code. The [**Developer Guide**](guide/index.html)
shows you how.