a1-a2 quick ref copy edits (#2255)

* a1-a2 quick ref copy edits

* copy edits, 2nd pass

* Glossary Edits

* 1-2 quick ref copy edits, pass 2
This commit is contained in:
Kapunahele Wong 2016-09-13 17:56:29 -04:00 committed by Kathy Walrath
parent 07cfce795f
commit c5a1a88042
3 changed files with 258 additions and 293 deletions

View File

@ -2,31 +2,29 @@ include ../_util-fns
a(id="top")
:marked
There are many conceptual and syntactical differences between Angular 1 and Angular 2.
This chapter provides a quick reference guide to some of the common Angular 1
This page provides a quick guide to some common Angular 1
syntax and its equivalent in Angular 2.
:marked
**See the Angular 2 syntax in this <live-example name="cb-a1-a2-quick-reference"></live-example>**.
## Contents
This chapter covers
* [Template Basics](#template-basics) - binding and local variables
This page covers:
* [Template basics](#template-basics) - binding and local variables.
* [Template Directives](#template-directives) - built-in directives `ngIf` and `ngClass`
* [Template directives](#template-directives) - built-in directives `ngIf` and `ngClass`.
* [Filters/Pipes](#filters-pipes) - built-in *filters*, known as *pipes* in Angular&nbsp;2
* [Filters/pipes](#filters-pipes) - built-in *filters*, known as *pipes* in Angular&nbsp;2.
* [Modules/Controllers/Components](#controllers-components) - *modules* are *modules* but different
and *controllers* are *components* in Angular&nbsp;2.
* [Modules/controllers/components](#controllers-components) - *modules* in Angular&nbsp;2 are slightly different from *modules* in Angular&nbsp;1, and *controllers* are *components* in Angular&nbsp;2.
* [Style Sheets](#style-sheets) - more options for CSS in Angular&nbsp;2.
* [Style sheets](#style-sheets) - more options for CSS than in Angular&nbsp;1.
.l-main-section
:marked
## Template Basics
## Template basics
Templates are the user-facing part of an Angular application and are written in HTML.
The following are some of the key Angular&nbsp;1 template features with the equivalent
template syntax in Angular&nbsp;2.
The following table lists some of the key Angular&nbsp;1 template features with their equivalent Angular&nbsp;2 template syntax.
- var top="vertical-align:top"
table(width="100%")
@ -38,7 +36,7 @@ table(width="100%")
tr(style=top)
td
:marked
### Bindings/Interpolation
### Bindings/interpolation
code-example.
Your favorite hero is: {{vm.favoriteHero}}
:marked
@ -47,11 +45,11 @@ table(width="100%")
associated with this template.
When using the `controller as` syntax,
the binding is prefixed with the controller alias (`vm` or `$ctrl`) because we
the binding is prefixed with the controller alias (`vm` or `$ctrl`) because you
have to be specific about the source of the binding.
td
:marked
### Bindings/Interpolation
### Bindings/interpolation
+makeExample('cb-a1-a2-quick-reference/ts/app/movie-list.component.html', 'interpolation')(format="." )
:marked
In Angular&nbsp;2, a template expression in curly braces still denotes one-way binding.
@ -59,7 +57,7 @@ table(width="100%")
The context of the binding is implied and is always the
associated component, so it needs no reference variable.
For more information see [Template Syntax](../guide/template-syntax.html#interpolation).
For more information, see the [Interpolation](../guide/template-syntax.html#interpolation) section of the Template Syntax page.
tr(style=top)
td
:marked
@ -67,19 +65,19 @@ table(width="100%")
code-example.
&lt;td>{{movie.title | uppercase}}&lt;/td>
:marked
To filter output in our templates in Angular&nbsp;1, we use the pipe character (|) and one or more filters.
To filter output in Angular&nbsp;1 templates, use the pipe character (|) and one or more filters.
In this example, we filter the `title` property to uppercase.
This example filters the `title` property to uppercase.
td
:marked
### Pipes
+makeExample('cb-a1-a2-quick-reference/ts/app/app.component.html', 'uppercase')(format="." )
:marked
In Angular&nbsp;2, we use similar syntax with the pipe (|) character to filter output, but now we call them **pipes**.
In Angular&nbsp;2 you use similar syntax with the pipe (|) character to filter output, but now you call them **pipes**.
Many (but not all) of the built-in filters from Angular&nbsp;1 are
built-in pipes in Angular&nbsp;2.
See the heading [Filters / Pipes](#Pipes) below for more information.
For more information, see the heading [Filters/pipes](#Pipes) below.
tr(style=top)
td
:marked
@ -95,18 +93,18 @@ table(width="100%")
### Input variables
+makeExample('cb-a1-a2-quick-reference/ts/app/app.component.html', 'local')(format="." )
:marked
In Angular&nbsp;2, we have true template input variables that are explicitly defined using the `let` keyword.
Angular&nbsp;2 has true template input variables that are explicitly defined using the `let` keyword.
For more information see [ngFor micro-syntax](../guide/template-syntax.html#ngForMicrosyntax).
For more information, see the [ngFor micro-syntax](../guide/template-syntax.html#ngForMicrosyntax) section of the Template Syntax page.
:marked
[Back to top](#top)
.l-main-section
:marked
## Template Directives
Angular&nbsp;1 provides over seventy built-in directives for use in our templates.
Many of them are no longer needed in Angular&nbsp;2 because of its more capable and expressive binding system.
The following are some of the key Angular&nbsp;1 built-in directives and the equivalent feature in Angular&nbsp;2.
## Template directives
Angular&nbsp;1 provides more than seventy built-in directives for templates.
Many of them aren't needed in Angular&nbsp;2 because of its more capable and expressive binding system.
The following are some of the key Angular&nbsp;1 built-in directives and their equivalents in Angular&nbsp;2.
table(width="100%")
col(width="50%")
@ -123,7 +121,7 @@ table(width="100%")
:marked
The application startup process is called **bootstrapping**.
Although we can bootstrap an Angular&nbsp;1 app in code,
Although you can bootstrap an Angular&nbsp;1 app in code,
many applications bootstrap declaratively with the `ng-app` directive,
giving it the name of the application's module (`movieHunter`).
td
@ -134,8 +132,8 @@ table(width="100%")
+makeExample('cb-a1-a2-quick-reference/ts/app/app.module.1.ts','','app.module.ts')(format="." )
:marked
Angular&nbsp;2 does not have a bootstrap directive.
We always launch the app in code by explicitly bootstrapping the application's root module (`AppModule`)
Angular&nbsp;2 doesn't have a bootstrap directive.
To launch the app in code, explicitly bootstrap the application's root module (`AppModule`)
in `main.ts`
and the application's root component (`AppComponent`) in `app.module.ts`.
@ -156,7 +154,7 @@ table(width="100%")
In the first example, the `active` class is applied to the element if `isActive` is true.
We can specify multiple classes as shown in the second example.
You can specify multiple classes, as shown in the second example.
td
:marked
### ngClass
@ -167,12 +165,12 @@ table(width="100%")
In the first example, the `active` class is applied to the element if `isActive` is true.
We can specify multiple classes as shown in the second example.
You can specify multiple classes, as shown in the second example.
Angular&nbsp;2 also has **class binding**, which is a good way to add or remove a single class
Angular&nbsp;2 also has **class binding**, which is a good way to add or remove a single class,
as shown in the third example.
For more information see [Template Syntax](../guide/template-syntax.html#other-bindings).
For more information see the [Attribute, Class, and Style Bindings](../guide/template-syntax.html#other-bindings) section of the Template Syntax page.
tr(style=top)
td
@ -182,9 +180,9 @@ table(width="100%")
&lt;button ng-click="vm.toggleImage()">
&lt;button ng-click="vm.toggleImage($event)">
:marked
In Angular&nbsp;1, the `ng-click` directive allows us to specify custom behavior when an element is clicked.
In Angular&nbsp;1, the `ng-click` directive allows you to specify custom behavior when an element is clicked.
In the first example, when the button is clicked, the `toggleImage()` method in the controller referenced by the `vm` `controller as` alias is executed.
In the first example, when the user clicks the button, the `toggleImage()` method in the controller referenced by the `vm` `controller as` alias is executed.
The second example demonstrates passing in the `$event` object, which provides details about the event
to the controller.
@ -193,22 +191,22 @@ table(width="100%")
### bind to the `click` event
+makeExample('cb-a1-a2-quick-reference/ts/app/app.component.html', 'event-binding')(format="." )
:marked
The Angular&nbsp;1 event-based directives do not exist in Angular&nbsp;2.
Rather, we define one-way binding from the template view to the component using **event binding**.
Angular&nbsp;1 event-based directives do not exist in Angular&nbsp;2.
Rather, define one-way binding from the template view to the component using **event binding**.
For event binding, we define the name of the target event within parenthesis and
specify a template statement in quotes to the right of the equals. Angular&nbsp;2 then
For event binding, define the name of the target event within parenthesis and
specify a template statement, in quotes, to the right of the equals. Angular&nbsp;2 then
sets up an event handler for the target event. When the event is raised, the handler
executes the template statement.
In the first example, when the button is clicked, the `toggleImage()` method in the associated component is executed.
In the first example, when a user clicks the button, the `toggleImage()` method in the associated component is executed.
The second example demonstrates passing in the `$event` object, which provides details about the event
to the component.
For a list of DOM events, see: https://developer.mozilla.org/en-US/docs/Web/Events.
For more information see [Template Syntax](../guide/template-syntax.html#event-binding).
For more information, see the [Event Binding](../guide/template-syntax.html#event-binding) section of the Template Syntax page.
tr(style=top)
td
@ -228,19 +226,19 @@ table(width="100%")
In Angular&nbsp;2, the template no longer specifies its associated controller.
Rather, the component specifies its associated template as part of the component class decorator.
For more information see [Architecture Overview](../guide/architecture.html#component).
For more information, see [Architecture Overview](../guide/architecture.html#component).
tr(style=top)
td
:marked
### ng-hide
In Angular&nbsp;1, the `ng-hide` directive shows or hides the associated HTML element based on
an expression. See [ng-show](#ng-show) for more information.
an expression. For more information, see [ng-show](#ng-show).
td
:marked
### bind to the `hidden` property
In Angular&nbsp;2, we use property binding; there is no built-in *hide* directive.
See [ng-show](#ng-show) for more information.
In Angular&nbsp;2, you use property binding; there is no built-in *hide* directive.
For more information, see [ng-show](#ng-show).
tr(style=top)
td
:marked
@ -248,7 +246,7 @@ table(width="100%")
code-example(format="").
&lt;a ng-href="angularDocsUrl">Angular Docs&lt;/a>
:marked
The `ng-href` directive allows Angular&nbsp;1 to preprocess the `href` property so it
The `ng-href` directive allows Angular&nbsp;1 to preprocess the `href` property so that it
can replace the binding expression with the appropriate URL before the browser
fetches from that URL.
@ -262,15 +260,15 @@ table(width="100%")
### bind to the `href` property
+makeExample('cb-a1-a2-quick-reference/ts/app/app.component.html', 'href')(format="." )
:marked
In Angular&nbsp;2, we use property binding; there is no built-in *href* directive.
We place the element's `href` property in square brackets and set it to a quoted template expression.
Angular&nbsp;2, uses property binding; there is no built-in *href* directive.
Place the element's `href` property in square brackets and set it to a quoted template expression.
For more information on property binding see [Template Syntax](../guide/template-syntax.html#property-binding).
For more information on property binding, see [Template Syntax](../guide/template-syntax.html#property-binding).
In Angular&nbsp;2, `href` is no longer used for routing. Routing uses `routerLink` as shown in the third example.
In Angular&nbsp;2, `href` is no longer used for routing. Routing uses `routerLink`, as shown in the third example.
+makeExample('cb-a1-a2-quick-reference/ts/app/app.component.html', 'router-link')(format="." )
:marked
For more information on routing see [Routing & Navigation](../guide/router.html#router-link).
For more information on routing, see [Routing & Navigation](../guide/router.html#router-link).
tr(style=top)
td
@ -279,7 +277,7 @@ table(width="100%")
code-example(format="").
&lt;table ng-if="movies.length">
:marked
In Angular&nbsp;1, the `ng-if` directive removes or recreates a portion of the DOM
In Angular&nbsp;1, the `ng-if` directive removes or recreates a portion of the DOM,
based on an expression. If the expression is false, the element is removed from the DOM.
In this example, the `table` element is removed from the DOM unless the `movies` array has a length greater than zero.
@ -288,13 +286,12 @@ table(width="100%")
### *ngIf
+makeExample('cb-a1-a2-quick-reference/ts/app/movie-list.component.html', 'ngIf')(format="." )
:marked
The `*ngIf` directive in Angular&nbsp;2 works the same as the `ng-if` directive in Angular&nbsp;1,
it removes or recreates a portion of the DOM based on an expression.
The `*ngIf` directive in Angular&nbsp;2 works the same as the `ng-if` directive in Angular&nbsp;1. It removes or recreates a portion of the DOM based on an expression.
In this example, the `table` element is removed from the DOM unless the `movies` array has a length.
The (*) before `ngIf` is required in this example.
For more information see [Structural Directives](../guide/structural-directives.html).
For more information, see [Structural Directives](../guide/structural-directives.html).
tr(style=top)
td
:marked
@ -303,18 +300,16 @@ table(width="100%")
&lt;input ng-model="vm.favoriteHero"/>
:marked
In Angular&nbsp;1, the `ng-model` directive binds a form control to a property in the controller associated with the template.
This provides **two-way binding** whereby any changes made to the value in the view is synchronized with the model and
any changes to the model are synchronized with the value in the view.
This provides **two-way binding**, whereby any change made to the value in the view is synchronized with the model, and any change to the model is synchronized with the value in the view.
td
:marked
### ngModel
+makeExample('cb-a1-a2-quick-reference/ts/app/movie-list.component.html', 'ngModel')(format="." )
:marked
In Angular&nbsp;2, **two-way binding** is denoted with [()], descriptively referred to as a "banana in a box".
This syntax is a short-cut for defining both property binding (from the component to the view)
and event binding (from the view to the component), thereby giving us two-way binding.
In Angular&nbsp;2, **two-way binding** is denoted by `[()]`, descriptively referred to as a "banana in a box". This syntax is a shortcut for defining both property binding (from the component to the view)
and event binding (from the view to the component), thereby providing two-way binding.
For more information on two-way binding with ngModel see [Template Syntax](../guide/template-syntax.html#ngModel).
For more information on two-way binding with ngModel, see [Template Syntax](../guide/template-syntax.html#ngModel).
tr(style=top)
td
:marked
@ -323,16 +318,15 @@ table(width="100%")
&lt;tr ng-repeat="movie in vm.movies">
:marked
In Angular&nbsp;1, the `ng-repeat` directive repeats the associated DOM element
for each item from the specified collection.
for each item in the specified collection.
In this example, the table row (`tr`) element is repeated for each movie object in the collection of movies.
In this example, the table row (`tr`) element repeats for each movie object in the collection of movies.
td
:marked
### *ngFor
+makeExample('cb-a1-a2-quick-reference/ts/app/movie-list.component.html', 'ngFor')(format="." )
:marked
The `*ngFor` directive in Angular&nbsp;2 is similar to the `ng-repeat` directive in Angular&nbsp;1.
It repeats the associated DOM element for each item from the specified collection.
The `*ngFor` directive in Angular&nbsp;2 is similar to the `ng-repeat` directive in Angular&nbsp;1. It repeats the associated DOM element for each item in the specified collection.
More accurately, it turns the defined element (`tr` in this example) and its contents into a template and
uses that template to instantiate a view for each item in the list.
@ -341,7 +335,7 @@ table(width="100%")
the `let` keyword identifies `movie` as an input variable;
the list preposition is `of`, not `in`.
For more information see [Structural Directives](../guide/structural-directives.html).
For more information, see [Structural Directives](../guide/structural-directives.html).
tr(style=top)
td
:marked
@ -351,7 +345,7 @@ table(width="100%")
Your favorite hero is: {{vm.favoriteHero}}
&lt;/h3>
:marked
In Angular&nbsp;1, the `ng-show` directive shows or hides the associated DOM element based on
In Angular&nbsp;1, the `ng-show` directive shows or hides the associated DOM element, based on
an expression.
In this example, the `div` element is shown if the `favoriteHero` variable is truthy.
@ -360,15 +354,15 @@ table(width="100%")
### bind to the `hidden` property
+makeExample('cb-a1-a2-quick-reference/ts/app/movie-list.component.html', 'hidden')(format="." )
:marked
In Angular&nbsp;2, we use property binding; there is no built-in *show* directive.
For hiding and showing elements, we bind to the HTML `hidden` property.
Angular&nbsp;2, uses property binding; there is no built-in *show* directive.
For hiding and showing elements, bind to the HTML `hidden` property.
To conditionally display an element, place the element's `hidden` property in square brackets and
set it to a quoted template expression that evaluates to the *opposite* of *show*.
In this example, the `div` element is hidden if the `favoriteHero` variable is not truthy.
For more information on property binding see [Template Syntax](../guide/template-syntax.html#property-binding).
For more information on property binding, see [Template Syntax](../guide/template-syntax.html#property-binding).
tr(style=top)
td
:marked
@ -376,7 +370,7 @@ table(width="100%")
code-example(format="").
&lt;img ng-src="{{movie.imageurl}}">
:marked
The `ng-src` directive allows Angular&nbsp;1 to preprocess the `src` property so it
The `ng-src` directive allows Angular&nbsp;1 to preprocess the `src` property so that it
can replace the binding expression with the appropriate URL before the browser
fetches from that URL.
td
@ -384,10 +378,10 @@ table(width="100%")
### bind to the `src` property
+makeExample('cb-a1-a2-quick-reference/ts/app/app.component.html', 'src')(format="." )
:marked
In Angular&nbsp;2, we use property binding; there is no built-in *src* directive.
We place the `src` property in square brackets and set it to a quoted template expression.
Angular&nbsp;2, uses property binding; there is no built-in *src* directive.
Place the `src` property in square brackets and set it to a quoted template expression.
For more information on property binding see [Template Syntax](../guide/template-syntax.html#property-binding).
For more information on property binding, see [Template Syntax](../guide/template-syntax.html#property-binding).
tr(style=top)
td
:marked
@ -412,9 +406,9 @@ table(width="100%")
Angular&nbsp;2 also has **style binding**, which is good way to set a single style. This is shown in the second example.
For more information on style binding see [Template Syntax](../guide/template-syntax.html#style-binding).
For more information on style binding, see [Template Syntax](../guide/template-syntax.html#style-binding).
For more information on the ngStyle directive see [Template Syntax](../guide/template-syntax.html#ngStyle).
For more information on the ngStyle directive, see [Template Syntax](../guide/template-syntax.html#ngStyle).
tr(style=top)
td
:marked
@ -437,7 +431,7 @@ table(width="100%")
an element by selecting one of the templates based on the current value of an expression.
In this example, if `favoriteHero` is not set, the template displays "Please enter ...".
If the `favoriteHero` is set, it checks the movie hero by calling a controller method.
If `favoriteHero` is set, it checks the movie hero by calling a controller method.
If that method returns `true`, the template displays "Excellent choice!".
If that methods returns `false`, the template displays "No movie, sorry!".
td
@ -449,24 +443,24 @@ table(width="100%")
It displays an element whose `*ngSwitchCase` matches the current `ngSwitch` expression value.
In this example, if `favoriteHero` is not set, the `ngSwitch` value is `null`
and we see the `*ngSwitchDefault` paragraph, "Please enter ...".
If the `favoriteHero` is set, it checks the movie hero by calling a component method.
If that method returns `true`, we see "Excellent choice!".
If that methods returns `false`, we see "No movie, sorry!".
and `*ngSwitchDefault` displays, "Please enter ...".
If `favoriteHero` is set, the app checks the movie hero by calling a component method.
If that method returns `true`, the app selects `*ngSwitchCase="true"` and displays: "Excellent choice!"
If that methods returns `false`, the app selects `*ngSwitchCase="false"` and displays: "No movie, sorry!"
The (*) before `ngSwitchCase` and `ngSwitchDefault` is required in this example.
For more information on the ngSwitch directive see [Template Syntax](../guide/template-syntax.html#ngSwitch).
For more information on the ngSwitch directive, see [Template Syntax](../guide/template-syntax.html#ngSwitch).
:marked
[Back to top](#top)
a(id="filters-pipes")
.l-main-section
:marked
## Filters / Pipes
## Filters/pipes
Angular&nbsp;2 **pipes** provide formatting and transformation for data in our template, similar to Angular&nbsp;1 **filters**.
Many of the built-in filters in Angular&nbsp;1 have corresponding pipes in Angular&nbsp;2.
For more information on pipes see [Pipes](../guide/pipes.html).
For more information on pipes, see [Pipes](../guide/pipes.html).
table(width="100%")
col(width="50%")
@ -510,14 +504,11 @@ table(width="100%")
code-example.
&lt;tr ng-repeat="movie in movieList | filter: {title:listFilter}">
:marked
Selects a subset of items from the defined collection based on the filter criteria.
Selects a subset of items from the defined collection, based on the filter criteria.
td
:marked
### none
There is no comparable pipe in Angular&nbsp;2 for performance reasons.
Filtering should be coded in the component.
Consider building a custom pipe if the same filtering code
will be reused in several templates.
For performance reasons, no comparable pipe exists in Angular&nbsp;2. Do all your filtering in the component. If you need the same filtering code in several templates, consider building a custom pipe.
tr(style=top)
td
@ -547,10 +538,10 @@ table(width="100%")
### slice
+makeExample('cb-a1-a2-quick-reference/ts/app/app.component.html', 'slice')(format=".")
:marked
The `SlicePipe` does the same thing but the *order of the parameters is reversed* in keeping
The `SlicePipe` does the same thing but the *order of the parameters is reversed*, in keeping
with the JavaScript `Slice` method.
The first parameter is the starting index; the second is the limit.
As in Angular 1, performance may improve if we code this operation within the component instead.
As in Angular 1, coding this operation within the component instead could improve performance.
tr(style=top)
td
:marked
@ -580,9 +571,9 @@ table(width="100%")
:marked
The Angular&nbsp;2 `number` pipe is similar.
It provides more functionality when defining
the decimal places as shown in the second example above.
the decimal places, as shown in the second example above.
Angular 2 also has a `percent` pipe which formats a number as a local percentage
Angular 2 also has a `percent` pipe, which formats a number as a local percentage
as shown in the third example.
tr(style=top)
td
@ -591,29 +582,27 @@ table(width="100%")
code-example.
&lt;tr ng-repeat="movie in movieList | orderBy : 'title'">
:marked
Orders the collection as specified by the expression.
In this example, the movieList is ordered by the movie title.
Displays the collection in the order specified by the expression.
In this example, the movie title orders the movieList.
td
:marked
### none
There is no comparable pipe in Angular&nbsp;2 for performance reasons.
Ordering/sorting the results should be coded in the component.
Consider building a custom pipe if the same ordering/sorting code
will be reused in several templates.
For performance reasons, no comparable pipe exists in Angular&nbsp;2.
Instead, use component code to order or sort results. If you need the same ordering or sorting code in several templates, consider building a custom pipe.
:marked
[Back to top](#top)
a(id="controllers-components")
.l-main-section
:marked
## Modules / Controllers / Components
In both Angular&nbsp;1 and Angular&nbsp;2, we use Angular modules to
help us organize our application into cohesive blocks of functionality.
## Modules/controllers/components
In both Angular&nbsp;1 and Angular&nbsp;2, Angular modules help you organize your application into cohesive blocks of functionality.
In Angular&nbsp;1, we write the code that provides the model and the methods for the view in a **controller**.
In Angular&nbsp;2, we build a **component**.
In Angular&nbsp;1, you write the code that provides the model and the methods for the view in a **controller**.
In Angular&nbsp;2, you build a **component**.
Because much of our Angular&nbsp;1 code is in JavaScript, JavaScript code is shown in the Angular&nbsp;1 column.
Because much Angular&nbsp;1 code is in JavaScript, JavaScript code is shown in the Angular&nbsp;1 column.
The Angular&nbsp;2 code is shown using TypeScript.
table(width="100%")
@ -631,15 +620,15 @@ table(width="100%")
...
}());
:marked
In Angular&nbsp;1, we often defined an immediately invoked function expression (or IIFE) around our controller code.
This kept our controller code out of the global namespace.
In Angular&nbsp;1, you often defined an immediately invoked function expression (or IIFE) around your controller code.
This kept your controller code out of the global namespace.
td
:marked
### none
We don't need to worry about this in Angular&nbsp;2 because we use ES 2015 modules
and modules handle the namespacing for us.
You don't need to worry about this in Angular&nbsp;2 because you use ES 2015 modules
and modules handle the namespacing for you.
For more information on modules see [Architecture Overview](../guide/architecture.html#module).
For more information on modules, see [Architecture Overview](../guide/architecture.html#module).
tr(style=top)
td
:marked
@ -647,9 +636,7 @@ table(width="100%")
code-example.
angular.module("movieHunter", ["ngRoute"]);
:marked
In Angular&nbsp;1, we define an Angular module, which keeps track of our
controllers, services, and other code. The second argument defines the list
of other modules that this module depends upon.
In Angular&nbsp;1, an Angular module keeps track of controllers, services, and other code. The second argument defines the list of other modules that this module depends upon.
td
:marked
### Angular modules
@ -657,9 +644,9 @@ table(width="100%")
:marked
Angular&nbsp;2 modules, defined with the `NgModule` decorator, serve the same purpose:
- `imports`: specifies the list of other modules that this module depends upon
- `declaration`: keeps track of our components, pipes, and directives.
- `declaration`: keeps track of your components, pipes, and directives.
For more information on modules see [Angular Modules](../guide/ngmodule.html).
For more information on modules, see [Angular Modules](../guide/ngmodule.html).
tr(style=top)
td
:marked
@ -671,7 +658,7 @@ table(width="100%")
["movieService",
MovieListCtrl]);
:marked
In Angular&nbsp;1, we have code in each controller that looks up an appropriate Angular module
Angular&nbsp;1, has code in each controller that looks up an appropriate Angular module
and registers the controller with that module.
The first argument is the controller name. The second argument defines the string names of
@ -681,13 +668,13 @@ table(width="100%")
### Component Decorator
+makeExample('cb-a1-a2-quick-reference/ts/app/movie-list.component.ts', 'component')(format=".")
:marked
In Angular&nbsp;2, we add a decorator to the component class to provide any required metadata.
Angular&nbsp;2, adds a decorator to the component class to provide any required metadata.
The Component decorator declares that the class is a component and provides metadata about
that component, such as its selector (or tag) and its template.
that component such as its selector (or tag) and its template.
This is how we associate a template with code, which is defined in the component class.
This is how you associate a template with code, which is defined in the component class.
For more information on components see [Architecture Overview](../guide/architecture.html#component).
For more information, see the [Components](../guide/architecture.html#components) section of the Architecture Overview page.
tr(style=top)
td
:marked
@ -696,18 +683,17 @@ table(width="100%")
function MovieListCtrl(movieService) {
}
:marked
In Angular&nbsp;1, we write the code for the model and methods in a controller function.
In Angular&nbsp;1, you write the code for the model and methods in a controller function.
td
:marked
### Component class
+makeExample('cb-a1-a2-quick-reference/ts/app/movie-list.component.ts', 'class')(format=".")
:marked
In Angular&nbsp;2, we create a component class.
In Angular&nbsp;2, you create a component class.
NOTE: If you are using TypeScript with Angular&nbsp;1 then the only difference here is
that the component class must be exported using the `export` keyword.
NOTE: If you are using TypeScript with Angular&nbsp;1, you must use the `export` keyword to export the component class.
For more information on components see [Architecture Overview](../guide/architecture.html#component).
For more information, see the [Components](../guide/architecture.html#components) section of the Architecture Overview page.
tr(style=top)
td
:marked
@ -717,34 +703,34 @@ table(width="100%")
function MovieListCtrl(movieService) {
}
:marked
In Angular&nbsp;1, we pass in any dependencies as controller function arguments.
In this example, we inject a `MovieService`.
In Angular&nbsp;1, you pass in any dependencies as controller function arguments.
This example injects a `MovieService`.
We also guard against minification problems by telling Angular explicitly
To guard against minification problems, tell Angular explicitly
that it should inject an instance of the `MovieService` in the first parameter.
td
:marked
### Dependency injection
+makeExample('cb-a1-a2-quick-reference/ts/app/movie-list.component.ts', 'di')(format=".")
:marked
In Angular&nbsp;2, we pass in dependencies as arguments to the component class constructor.
In this example, we inject a `MovieService`.
The first parameter's TypeScript type tells Angular what to inject even after minification.
In Angular&nbsp;2, you pass in dependencies as arguments to the component class constructor.
This example injects a `MovieService`.
The first parameter's TypeScript type tells Angular what to inject, even after minification.
For more information on dependency injection see [Architecture Overview](../guide/architecture.html#dependency-injection).
For more information, see the [Dependency Injection](../guide/architecture.html#dependency-injection) section of the Architecture Overview.
:marked
[Back to top](#top)
a(id="style-sheets")
.l-main-section
:marked
## Style Sheets
Style sheets give our application a nice look.
In Angular&nbsp;1, we specify the style sheets for our entire application.
## Style sheets
Style sheets give your application a nice look.
In Angular&nbsp;1, you specify the style sheets for your entire application.
As the application grows over time, the styles for the many parts of the application
are merged, which can cause unexpected results.
In Angular&nbsp;2, we can still define style sheets for our entire application. But now we can
also encapculate a style sheet within a specific component.
merge, which can cause unexpected results.
In Angular&nbsp;2, you can still define style sheets for your entire application. But now you can
also encapsulate a style sheet within a specific component.
table(width="100%")
col(width="50%")
col(width="50%")
@ -758,22 +744,22 @@ table(width="100%")
code-example.
&lt;link href="styles.css" rel="stylesheet" />
:marked
In Angular&nbsp;1, we use a `link` tag in the head section of our `index.html` file
to define the styles for our application.
Angular&nbsp;1, uses a `link` tag in the head section of the `index.html` file
to define the styles for the application.
td
:marked
### Link tag
+makeExample('cb-a1-a2-quick-reference/ts/index.html', 'style')(format=".")
:marked
In Angular&nbsp;2, we can continue to use the link tag to define the styles for our application in the `index.html` file.
But we can now also encapsulate styles for our components.
In Angular&nbsp;2, you can continue to use the link tag to define the styles for your application in the `index.html` file.
But now you can also encapsulate styles for your components.
:marked
### StyleUrls
In Angular&nbsp;2, we can use the `styles` or `styleUrls` property of the `@Component` metadata to define
In Angular&nbsp;2, you can use the `styles` or `styleUrls` property of the `@Component` metadata to define
a style sheet for a particular component.
+makeExample('cb-a1-a2-quick-reference/ts/app/movie-list.component.ts', 'style-url')(format=".")
:marked
This allows us to set appropriate styles for individual components that wont leak into
This allows you to set appropriate styles for individual components that wont leak into
other parts of the application.
:marked
[Back to top](#top)

View File

@ -15,7 +15,7 @@ block includes
Most Angular 2 terms are everyday English words
with a specific meaning within the Angular system.
We have gathered here the most prominent terms
This glossary lists the most prominent terms
and a few less familiar ones that have unusual or
unexpected definitions.
@ -31,9 +31,9 @@ block includes
## Ahead of Time (AOT) Compilation
.l-sub-section
:marked
Angular applications can be compiled by developers at build-time.
You can compile Angular applications at build-time.
By compiling your application using the compiler-cli, `ngc`, you can bootstrap directly
to a Module Factory, meaning you don't need to include the Angular compiler in your javascript bundle.
to a Module Factory, meaning you don't need to include the Angular compiler in your Javascript bundle.
Ahead of Time compiled applications also benefit from decreased load time and increased performance.
:marked
@ -41,13 +41,12 @@ block includes
.l-sub-section
:marked
Helps us organize an application into cohesive blocks of functionality.
An Angular module identifies the components, directives, and pipes that are used by the application
along with the list of external Angular modules that the application needs, such as `FormsModule`.
An Angular module identifies the components, directives, and pipes that the application uses along with the list of external Angular modules that the application needs, such as `FormsModule`.
Every Angular application has an application root module class. By convention the class is
Every Angular application has an application root module class. By convention, the class is
called `AppModule` and resides in a file named `app.component.ts`.
See the [Angular Module](!{docsLatest}/guide/ngmodule.html) chapter for details and examples.
For details and examples, see the [Angular Module](!{docsLatest}/guide/ngmodule.html) page.
+ifDocsFor('ts|dart')
:marked
@ -65,8 +64,7 @@ block includes
other HTML elements, attributes, properties, and components. They are usually represented
as HTML attributes, hence the name.
The `ngClass` directive for adding and removing CSS class names is a good example of
an Attribute Directive.
A good example of an Attribute Directive is the `ngClass` directive for adding and removing CSS class names.
.l-main-section#B
@ -75,7 +73,7 @@ block includes
## Barrel
.l-sub-section
:marked
A barrel is a way to *rollup exports* from several ES2015 modules into a single convenience ES2015 module.
A barrel is a way to *rollup exports* from several ES2015 modules into a single convenient ES2015 module.
The barrel itself is an ES2015 module file that re-exports *selected* exports of other ES2015 modules.
Imagine three ES2015 modules in a `heroes` folder:
@ -95,13 +93,13 @@ block includes
import { Hero } from '../heroes/hero.model.ts';
import { HeroService } from '../heroes/hero.service.ts';
:marked
We can add a barrel to the `heroes` folder (called `index` by convention) that exports all of these items:
You can add a barrel to the `heroes` folder (called `index`, by convention) that exports all of these items:
code-example.
export * from './hero.model.ts'; // re-export all of its exports
export * from './hero.service.ts'; // re-export all of its exports
export { HeroComponent } from './hero.component.ts'; // re-export the named thing
:marked
Now a consumer can import what it needs from the barrel.
Now a consumer can import what they need from the barrel.
code-example.
import { Hero, HeroService } from '../heroes'; // index is implied
:marked
@ -113,7 +111,7 @@ block includes
.alert.is-important
:marked
Note that you can often achieve this same goal using [Angular modules](#angular-module) instead.
Note that you can often achieve this using [Angular modules](#angular-module) instead.
:marked
## Binding
@ -123,7 +121,7 @@ block includes
binding an HTML object property to a data object property.
May refer to a [Dependency Injection](#dependency-injection) binding
between a "token" or "key" and a dependency [provider](#provider).
between a "token", also referred to as a "key", and a dependency [provider](#provider).
This more rare usage should be clear in context.
:marked
@ -131,11 +129,11 @@ block includes
.l-sub-section
block bootstrap-defn-top
:marked
We launch an Angular application by "bootstrapping" it using the application root Angular module (`AppModule`).
The bootstraping identifies an application's top level "root" [Component](#component), which is the first
component that is loaded for the application. For more information see the [QuickStart](!{docsLatest}/quickstart.html).
You launch an Angular application by "bootstrapping" it using the application root Angular module (`AppModule`).
Bootstrapping identifies an application's top level "root" [Component](#component), which is the first
component that is loaded for the application. For more information, see [QuickStart](!{docsLatest}/quickstart.html).
:marked
One can bootstrap multiple apps in the same `index.html`, each with its own top level root.
You can bootstrap multiple apps in the same `index.html`, each with its own top level root.
.l-main-section#C
:marked
@ -143,12 +141,12 @@ block includes
.l-sub-section
:marked
The practice of writing compound words or phrases such that each word or abbreviation begins with a capital letter
_except the first letter which is a lowercase letter_.
_except the first letter which is lowercase_.
Function, property, and method names are typically spelled in camelCase. Examples include: `square`, `firstName` and `getHeroes`.
Function, property, and method names are typically spelled in camelCase. Examples include: `square`, `firstName` and `getHeroes`. Notice that `square` is an example of how you write a single word in camelCase.
This form is also known as **lower camel case**, to distinguish it from **upper camel case** which we call [PascalCase](#pascalcase).
When we write "camelCase" in this documentation we always mean *lower camel case*.
This form is also known as **lower camel case**, to distinguish it from **upper camel case** which is [PascalCase](#pascalcase).
When you see "camelCase" in this documentation it always means *lower camel case*.
:marked
## Component
@ -158,10 +156,10 @@ block includes
to a [View](#view) and handling most of the views display
and user-interaction logic.
The Component is one of the most important building blocks in the Angular system.
The *Component* is one of the most important building blocks in the Angular system.
It is, in fact, an Angular [Directive](#directive) with a companion [Template](#template).
The developer applies the `!{_at}Component` !{_decoratorLink} to
You apply the `!{_at}Component` !{_decoratorLink} to
the component class, thereby attaching to the class the essential component metadata
that Angular needs to create a component instance and render it with its template
as a view.
@ -188,28 +186,24 @@ block includes
Applications display data values to a user and respond to user
actions (clicks, touches, keystrokes).
We could push application data values into HTML, attach
event listeners, pull changed values from the screen, and
update application data values ... all by hand.
Or we could declare the relationship between an HTML widget
and an application data source ... and let a data binding
Instead of manually pushing application data values into HTML, attaching
event listeners, pulling changed values from the screen, and
updating application data values, you can use data binding by declaring the relationship between an HTML widget and data source and let the
framework handle the details.
Data Binding is that second approach. Angular has a rich
data binding framework with a variety of data binding
Angular has a rich data binding framework with a variety of data binding
operations and supporting declaration syntax.
The many forms of binding include:
* [Interpolation](!{docsLatest}/guide/template-syntax.html#interpolation)
* [Property Binding](!{docsLatest}/guide/template-syntax.html#property-binding)
* [Event Binding](!{docsLatest}/guide/template-syntax.html#event-binding)
* [Attribute Binding](!{docsLatest}/guide/template-syntax.html#attribute-binding)
* [Class Binding](!{docsLatest}/guide/template-syntax.html#class-binding)
* [Style Binding](!{docsLatest}/guide/template-syntax.html#style-binding)
* [Two-way data binding with ngModel](!{docsLatest}/guide/template-syntax.html#ng-model)
* [Interpolation](!{docsLatest}/guide/template-syntax.html#interpolation).
* [Property Binding](!{docsLatest}/guide/template-syntax.html#property-binding).
* [Event Binding](!{docsLatest}/guide/template-syntax.html#event-binding).
* [Attribute Binding](!{docsLatest}/guide/template-syntax.html#attribute-binding).
* [Class Binding](!{docsLatest}/guide/template-syntax.html#class-binding).
* [Style Binding](!{docsLatest}/guide/template-syntax.html#style-binding).
* [Two-way data binding with ngModel](!{docsLatest}/guide/template-syntax.html#ng-model).
Learn more about data binding in the
Read more about data binding in the
[Template Syntax](!{docsLatest}/guide/template-syntax.html#data-binding) chapter.
+ifDocsFor('ts|dart')
@ -224,14 +218,12 @@ block includes
Decorators are a JavaScript language [feature](https://github.com/wycats/javascript-decorators), implemented in TypeScript and proposed for ES2016 (AKA ES7).
We apply a decorator by positioning it
immediately above or to the left of the thing it decorates.
To apply a decorator, position it immediately above or to the left of the thing it decorates.
Angular has its own set of decorators to help it interoperate with our application parts.
Angular has its own set of decorators to help it interoperate with your application parts.
Here is an example of a `@Component` decorator that identifies a
class as an Angular [Component](#component) and an `@Input` decorator applied to a property
of that component.
The elided object argument to the `@Component` decorator would contain the pertinent component metadata.
class as an Angular [Component](#component) and an `@Input` decorator applied to the `name` property
of that component. The elided object argument to the `@Component` decorator would contain the pertinent component metadata.
```
@Component({...})
export class AppComponent {
@ -245,8 +237,7 @@ block includes
.alert.is-important
:marked
Always include the parentheses `()` when applying a decorator.
A decorator is a **function** that must be called when applied.
Always include parentheses `()` when applying a decorator.
:marked
## Dependency Injection
@ -257,14 +248,14 @@ block includes
parts of an application that request them.
Angular developers prefer to build applications by defining many simple parts
that each do one thing well and then wire them together at runtime.
that each do one thing well and then wiring them together at runtime.
These parts often rely on other parts. An Angular [Component](#component)
part might rely on a service part to get data or perform a calculation. When a
part "A" relies on another part "B", we say that "A" depends on "B" and
These parts often rely on other parts. An Angular [component](#component)
part might rely on a service part to get data or perform a calculation. When
part "A" relies on another part "B", you say that "A" depends on "B" and
that "B" is a dependency of "A".
We can ask a "Dependency Injection System" to create "A"
You can ask a "Dependency Injection System" to create "A"
for us and handle all the dependencies.
If "A" needs "B" and "B" needs "C", the system resolves that chain of dependencies
and returns a fully prepared instance of "A".
@ -277,13 +268,12 @@ block includes
At the core there is an [`Injector`](#injector) that returns dependency values on request.
The expression `injector.get(token)` returns the value associated with the given token.
A token is an Angular type (`OpaqueToken`). We rarely deal with tokens directly; most
A token is an Angular type (`OpaqueToken`). You rarely deal with tokens directly; most
methods accept a class name (`Foo`) or a string ("foo") and Angular converts it
to a token. When we write `injector.get(Foo)`, the injector returns
to a token. When you write `injector.get(Foo)`, the injector returns
the value associated with the token for the `Foo` class, typically an instance of `Foo` itself.
Angular makes similar requests internally during many of its operations
as when it creates a [`Component`](#component) for display.
During many of its operations, Angular makes similar requests internally, such as when it creates a [`Component`](#component) for display.
The `Injector` maintains an internal map of tokens to dependency values.
If the `Injector` can't find a value for a given token, it creates
@ -299,23 +289,23 @@ block includes
Angular registers some of its own providers with every injector.
We can register our own providers.
Learn more in the [Dependency Injection](!{docsLatest}/guide/dependency-injection.html) chapter.
Learn more in the [Dependency Injection](!{docsLatest}/guide/dependency-injection.html) page.
:marked
## Directive
.l-sub-section
:marked
An Angular class responsible for creating, re-shaping, and interacting with HTML elements
An Angular class responsible for creating, reshaping, and interacting with HTML elements
in the browser DOM. Directives are Angular's most fundamental feature.
A Directive is almost always associated with an HTML element or attribute.
We often refer to such an element or attribute as the directive itself.
When Angular finds a directive in an HTML template,
it creates the matching directive class instance
and gives that instance control over that portion of the browser DOM.
and gives the instance control over that portion of the browser DOM.
Developers can invent custom HTML markup (e.g., `<my-directive>`) to
associate with their custom directives. They add this custom markup to HTML templates
as if they were writing native HTML. In this way, directives become extensions of
You can invent custom HTML markup (e.g., `<my-directive>`) to
associate with your custom directives. You add this custom markup to HTML templates
as if you were writing native HTML. In this way, directives become extensions of
HTML itself.
Directives fall into one of three categories:
@ -330,7 +320,7 @@ block includes
as HTML attributes, hence the name.
1. [Structural Directives](#structural-directive), a directive responsible for
shaping or re-shaping HTML layout, typically by adding, removing, or manipulating
shaping or reshaping HTML layout, typically by adding, removing, or manipulating
elements and their children.
.l-main-section#E
@ -343,9 +333,9 @@ block includes
The latest approved version of JavaScript is
[ECMAScript 2016](http://www.ecma-international.org/ecma-262/7.0/)
(AKA "ES2016" or "ES7") and many Angular 2 developers will write their applications
(AKA "ES2016" or "ES7") and many Angular 2 developers write their applications
either in this version of the language or a dialect that strives to be
compatible with it such as [TypeScript](#typesScript).
compatible with it, such as [TypeScript](#typesScript).
Most modern browsers today only support the much older "ECMAScript 5" (AKA ES5) standard.
Applications written in ES2016, ES2015 or one of their dialects must be "[transpiled](#transpile)"
@ -391,7 +381,7 @@ a#H
Data values flow *into* this property from the data source identified
in the template expression to the right of the equal sign.
See the [Template Syntax](!{docsLatest}/guide/template-syntax.html#inputs-outputs) chapter.
See the [Template Syntax](!{docsLatest}/guide/template-syntax.html#inputs-outputs) page.
:marked
## Interpolation
@ -401,14 +391,14 @@ a#H
[template expression](#template-expression) between double-curly braces
renders as text. That text may be concatenated with neighboring text
before it is assigned to an element property
or displayed between element tags as in this example.
or displayed between element tags, as in this example.
code-example(language="html" escape="html").
<label>My current hero is {{hero.name}}</label>
:marked
Learn more about interpolation in the
[Template Syntax](!{docsLatest}/guide/template-syntax.html#interpolation) chapter.
Read more about interpolation in the
[Template Syntax](!{docsLatest}/guide/template-syntax.html#interpolation) page.
.l-main-section#J
@ -420,7 +410,7 @@ a#H
:marked
With Angular _Just in Time_ bootstrapping you compile your components and modules in the browser
and launch the application dynamically. This is a good choice during development.
Consider the [Ahead of Time](#aot) mode for production apps.
Consider using the [Ahead of Time](#aot) mode for production apps.
.l-main-section#K
:marked
@ -435,25 +425,25 @@ a#H
.l-sub-section
:marked
[Directives](#directive) and [Components](#component) have a lifecycle
managed by Angular as it creates, updates and destroys them.
managed by Angular as it creates, updates, and destroys them.
Developers can tap into key moments in that lifecycle by implementing
You can tap into key moments in that lifecycle by implementing
one or more of the "Lifecycle Hook" interfaces.
Each interface has a single hook method whose name is the interface name prefixed with `ng`.
For example, the `OnInit` interface has a hook method names `ngOnInit`.
For example, the `OnInit` interface has a hook method named `ngOnInit`.
Angular calls these hook methods in the following order:
* `ngOnChanges` - called when an [input](#input)/[output](#output) binding values change
* `ngOnInit` - after the first `ngOnChanges`
* `ngDoCheck` - developer's custom change detection
* `ngAfterContentInit` - after component content initialized
* `ngAfterContentChecked` - after every check of component content
* `ngAfterViewInit` - after component's view(s) are initialized
* `ngAfterViewChecked` - after every check of a component's view(s)
* `ngOnChanges` - when an [input](#input)/[output](#output) binding value changes.
* `ngOnInit` - after the first `ngOnChanges`.
* `ngDoCheck` - developer's custom change detection.
* `ngAfterContentInit` - after component content initialized.
* `ngAfterContentChecked` - after every check of component content.
* `ngAfterViewInit` - after component's view(s) are initialized.
* `ngAfterViewChecked` - after every check of a component's view(s).
* `ngOnDestroy` - just before the directive is destroyed.
Learn more in the [Lifecycle Hooks](!{docsLatest}/guide/lifecycle-hooks.html) chapter.
Read more in the [Lifecycle Hooks](!{docsLatest}/guide/lifecycle-hooks.html) page.
.l-main-section#M
@ -465,14 +455,13 @@ a#H
:marked
In Angular, there are two types of modules:
- [Angular modules](#angular-module).
See the [Angular Module](!{docsLatest}/guide/ngmodule.html) chapter for details and examples.
- ES2015 modules as described in this section.
For details and examples, see the [Angular Module](!{docsLatest}/guide/ngmodule.html) page.
- ES2015 modules, as described in this section.
:marked
Angular apps are modular.
In general, we assemble our application from many modules, both the ones we write ourselves
and the ones we acquire from others.
In general, you assemble your application from many modules, both the ones you write and the ones you acquire from others.
A typical module is a cohesive block of code dedicated to a single purpose.
@ -480,21 +469,19 @@ a#H
A module that needs that thing, **imports** it.
The structure of Angular modules and the import/export syntax
is based on the [ES2015](#es2015) module standard
described [here](http://www.2ality.com/2014/09/es6-modules-final.html).
is based on the [ES2015 module standard](http://www.2ality.com/2014/09/es6-modules-final.html).
An application that adheres to this standard requires a module loader to
load modules on request and resolve inter-module dependencies.
load modules on request, and resolve inter-module dependencies.
Angular does not ship with a module loader and does not have a preference
for any particular 3rd party library (although most samples use SystemJS).
Application developers may pick any module library that conforms to the standard
for any particular 3rd party library (although most examples use SystemJS).
You may pick any module library that conforms to the standard.
Modules are typically named after the file in which the exported thing is defined.
The Angular [DatePipe](https://github.com/angular/angular/blob/master/modules/@angular/common/src/pipes/date_pipe.ts)
class belongs to a feature module named `date_pipe` in the file `date_pipe.ts`.
Developers rarely access Angular feature modules directly.
We usually import them from one of the Angular [scoped packages](#scoped-package) such as `@angular/core`.
You rarely access Angular feature modules directly. You usually import them from one of the Angular [scoped packages](#scoped-package) such as `@angular/core`.
a#N
.l-main-section#O
@ -504,8 +491,8 @@ a#N
## Observable
.l-sub-section
:marked
We can think of an observable as an array whose items arrive asynchronously over time.
Observables help us manage asynchronous data, such as data coming from a backend service.
You can think of an observable as an array whose items arrive asynchronously over time.
Observables help you manage asynchronous data, such as data coming from a backend service.
Observables are used within Angular itself, including Angular's event system and its http client service.
To use observables, Angular uses a third-party library called Reactive Extensions (RxJS).
@ -520,7 +507,7 @@ a#N
Events stream *out* of this property to the receiver identified
in the template expression to the right of the equal sign.
See the [Template Syntax](!{docsLatest}/guide/template-syntax.html#inputs-outputs) chapter.
See the [Template Syntax](!{docsLatest}/guide/template-syntax.html#inputs-outputs) page.
.l-main-section#P
@ -528,10 +515,9 @@ a#N
## PascalCase
.l-sub-section
:marked
The practice of writing compound words or phrases such that each word or abbreviation begins with a capital letter.
Class names are typically spelled in PascalCase. Examples include: `Person` and `HeroDetailComponent`.
The practice of writing individual words, compound words, or phrases such that each word or abbreviation begins with a capital letter. Class names are typically spelled in PascalCase. Examples include: `Person` and `HeroDetailComponent`.
This form is also known as **upper camel case**, to distinguish it from **lower camel case** which we simply call [camelCase](#camelcase).
This form is also known as **upper camel case** to distinguish it from **lower camel case** which we simply call [camelCase](#camelcase).
In this documentation, "PascalCase" means *upper camel case* and "camelCase" means *lower camel case*.
:marked
@ -539,9 +525,9 @@ a#N
.l-sub-section
:marked
An Angular pipe is a function that transforms input values to output values for
display in a [view](#view). We use the `!{_at}Pipe` !{_decoratorLink}
to associate the pipe function with a name. We can then use that
name in our HTML to declaratively transform values on screen.
display in a [view](#view). Use the `!{_at}Pipe` !{_decoratorLink}
to associate the pipe function with a name. You then use that
name in your HTML to declaratively transform values on screen.
Here's an example that uses the built-in `currency` pipe to display
a numeric value in the local currency.
@ -549,7 +535,7 @@ a#N
code-example(language="html" escape="html").
<label>Price: </label>{{product.price | currency}}
:marked
Learn more in the chapter on [pipes](!{docsLatest}/guide/pipes.html) .
Read more in the page on [pipes](!{docsLatest}/guide/pipes.html).
- var _ProviderUrl = docsLatest+'/api/'+(lang == 'dart' ? 'angular2.core' : 'core/index')+'/Provider-class.html'
:marked
@ -558,8 +544,7 @@ a#N
:marked
A [Provider](!{_ProviderUrl}) creates a new instance of a dependency for the
[Dependency Injection](#dependency-injection) system.
It relates a lookup token to code &mdash; sometimes called a "recipe" &mdash;
that can create a dependency value.
It relates a lookup token to code&mdash;sometimes called a "recipe"&mdash;that can create a dependency value.
a#Q
.l-main-section#R
@ -578,24 +563,22 @@ a#Q
- The template input elements do *not* use `ngModel`.
- The associated Angular directives are all prefixed with `Form` such as `FormGroup`, `FormControl`, and `FormControlName`.
Reactive forms are powerful, flexible, and great for more complex data entry form scenarios, such as dynamic generation
of form controls.
Reactive forms are powerful, flexible, and great for more complex data entry form scenarios such as dynamic generation of form controls.
:marked
## Router
.l-sub-section
:marked
Most applications consist of many screens or [views](#view).
The user navigates among them by clicking links and buttons
and taking other similar actions that cause the application to
The user navigates among them by clicking links and buttons,
and performing other similar actions that cause the application to
replace one view with another.
The Angular [Component Router](!{docsLatest}/guide/router.html) is a richly featured mechanism for configuring
and managing the entire view navigation process including the creation and destruction
The Angular [Component Router](!{docsLatest}/guide/router.html) is a richly featured mechanism for configuring and managing the entire view navigation process including the creation and destruction
of views.
+ifDocsFor('ts|js')
:marked
In most cases, components becomes attached to a [router](#router) by means
In most cases, components become attached to a [router](#router) by means
of a `RouterConfig` that defines routes to views.
A [routing component's](#routing-component) template has a `RouterOutlet` element
@ -604,7 +587,7 @@ a#Q
Other views in the application likely have anchor tags or buttons with `RouterLink`
directives that users can click to navigate.
See the [Component Router](!{docsLatest}/guide/router.html) chapter to learn more.
For more information, see the [Component Router](!{docsLatest}/guide/router.html) page.
+ifDocsFor('ts|js')
:marked
@ -613,7 +596,7 @@ a#Q
:marked
A separate [Angular module](#angular-module) that provides the necessary service providers and directives for navigating through application views.
See the [Component Router](!{docsLatest}/guide/router.html) chapter to learn more.
For more information, see the [Component Router](!{docsLatest}/guide/router.html) page.
:marked
## Routing Component
@ -622,7 +605,7 @@ a#Q
:marked
An Angular [Component](#component) with a RouterOutlet that displays views based on router navigations.
See the [Component Router](!{docsLatest}/guide/router.html) chapter to learn more.
For more information, see the [Component Router](!{docsLatest}/guide/router.html) page.
.l-main-section#S
@ -636,9 +619,9 @@ a#Q
A [*scoped package*](https://docs.npmjs.com/misc/scope) is a way to group related *npm* packages.
We import a scoped package the same way we'd import a *normal* package.
You import a scoped package the same way that you'd import a *normal* package.
The only difference, from a consumer perspective,
is that the package name begins with the Angular *scope name*, `@angular`.
is that the *scoped package* name begins with the Angular *scope name*, `@angular`.
+makeExcerpt('architecture/ts/app/app.component.ts', 'import', '')
@ -649,38 +632,34 @@ a#snake-case
.l-sub-section
block snake-case-defn
:marked
The practice of writing compound words or phrases such that each word is separated by an
underscore (`_`). This form is also known as **underscore case**.
The practice of writing compound words or phrases such that an
underscore (`_`) separates one word from the next. This form is also known as **underscore case**.
:marked
## Service
.l-sub-section
:marked
Components are great and all, but what do we do with data or logic that are not associated
with a specific view or that we want to share across components? We build services!
For data or logic that is not associated
with a specific view or that you want to share across components, build services.
Applications often require services such as a hero data service or a logging service.
Our components depend on these services to do the heavy lifting.
A service is a class with a focused purpose.
We often create a service to implement features that are
independent from any specific view,
provide share data or logic across components, or encapsulate external interactions.
provide shared data or logic across components, or encapsulate external interactions.
See the [Services](!{docsLatest}/tutorial/toh-pt4.html) chapter of the tutorial to learn more.
For more information, see the [Services](!{docsLatest}/tutorial/toh-pt4.html) page.
:marked
## Structural Directive
.l-sub-section
:marked
A category of [Directive](#directive) that can
shape or re-shape HTML layout, typically by adding, removing, or manipulating
elements and their children.
shape or reshape HTML layout, typically by adding, removing, or manipulating
elements and their children; for example, the `ngIf` "conditional element" directive and the `ngFor` "repeater" directive.
The `ngIf` "conditional element" directive and the `ngFor` "repeater" directive are
good examples in this category.
See the [Structural Directives](!{docsLatest}/guide/structural-directives.html) chapter to learn more.
Read more in the [Structural Directives](!{docsLatest}/guide/structural-directives.html) page.
.l-main-section#T
:marked
@ -691,7 +670,6 @@ a#snake-case
the support and continuing guidance of an Angular [Directive](#directive),
most notably a [Component](#component).
We write templates in a special [Template Syntax](!{docsLatest}/guide/template-syntax.html).
+ifDocsFor('ts|js')
:marked
@ -704,11 +682,10 @@ a#snake-case
When building template-driven forms:
- The "source of truth" is the template. The validation is defined using attributes on the individual input elements.
- [Two-way binding](#data-binding) with `ngModel` keeps the component model in synchronization with the user's entry into the input elements.
- Behind the scenes, Angular creates a new control for each input element that has a `name` attribute and
two-way binding set up.
- Behind the scenes, Angular creates a new control for each input element, provided you have set up a `name` attribute and two-way binding for each input.
- The associated Angular directives are all prefixed with `ng` such as `ngForm`, `ngModel`, and `ngModelGroup`.
Template-driven forms are convenient, quick, and simple and are a good choice for many basic data entry form scenarios.
Template-driven forms are convenient, quick, and simple. They are a good choice for many basic data entry form scenarios.
Learn how to build template-driven forms
in the [Forms](!{docsLatest}/guide/forms.html) chapter.
@ -718,33 +695,34 @@ a#snake-case
.l-sub-section
:marked
An expression is a !{_Lang}-like syntax that Angular evaluates within
a [data binding](#data-binding). Learn how to write template expressions
in the [Template Syntax](!{docsLatest}/guide/template-syntax.html#template-expressions) chapter.
a [data binding](#data-binding).
Read about how to write template expressions
in the [Template Syntax](!{docsLatest}/guide/template-syntax.html#template-expressions) page.
:marked
## Transpile
.l-sub-section
:marked
The process of transforming code written in one form of JavaScript
(e.g., TypeScript) into another form of JavaScript (e.g., [ES5](#es5)).
(for example, TypeScript) into another form of JavaScript (for example, [ES5](#es5)).
:marked
## TypeScript
.l-sub-section
:marked
A version of JavaScript that supports most [ECMAScript](#ecmascript) 2015
language features and many features that may arrive in future versions
of JavaScript such as [Decorators](#decorator).
A version of JavaScript that supports most [ECMAScript 2015](#ecmascript=2015)
language features such as [Decorators](#decorator).
TypeScript is also noteable for its optional typing system which gives
us compile-time type-checking and strong tooling support (e.g. "intellisense",
TypeScript is also noteable for its optional typing system, which gives
us compile-time type checking and strong tooling support (for example, "intellisense",
code completion, refactoring, and intelligent search). Many code editors
and IDEs support TypeScript either natively or with plugins.
TypeScript is the preferred language for Angular 2 development although
we are welcome to write in other JavaScript dialects such as [ES5](#es5).
you can use other JavaScript dialects such as [ES5](#es5).
Learn more about TypeScript on its [website](http://www.typescriptlang.org/).
Read more about TypeScript on its [website](http://www.typescriptlang.org/).
a#U
.l-main-section#V
@ -758,8 +736,8 @@ a#U
Angular renders a view under the control of one or more [Directives](#directive),
especially [Component](#component) directives and their companion [Templates](#template).
The Component plays such a prominent role that we often
find it convenient to refer to a component as a view.
The Component plays such a prominent role that it's often
convenient to refer to a component as a view.
Views often contain other views and any view might be loaded and unloaded
dynamically as the user navigates through the application, typically
@ -779,16 +757,16 @@ a#Y
a JavaScript application's asynchronous activity.
The browser DOM and JavaScript have a limited number
of asynchronous activities, activities such as DOM events (e.g., clicks),
of asynchronous activities, activities such as DOM events (for example, clicks),
[promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), and
[XHR](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest)
calls to remote servers.
Zones intercept all of these activities and give a "zone client" the opportunity
to take action before and after the async activity completes.
to take action before and after the async activity finishes.
Angular runs our application in a zone where it can respond to
asynchronous events by checking for data changes and updating
Angular runs your application in a zone where it can respond to
asynchronous events by checking for data changes, and updating
the information it displays via [data bindings](#data-binding).
Learn more about zones in this

View File

@ -154,6 +154,7 @@ figure
.l-main-section
:marked
<a id="components"></a>
## Components
figure
img(src="/resources/images/devguide/architecture/hero-component.png" alt="Component" align="left" style="width:200px; margin-left:-40px;margin-right:10px" )