diff --git a/aio/content/cookbook/ajs-quick-reference.md b/aio/content/cookbook/ajs-quick-reference.md index dcada58916..eb69ea22f4 100644 --- a/aio/content/cookbook/ajs-quick-reference.md +++ b/aio/content/cookbook/ajs-quick-reference.md @@ -2,7 +2,7 @@ AngularJS to Angular Quick Reference @intro -Learn how AngularJS concepts and techniques map to Angular +Learn how AngularJS concepts and techniques map to Angular. @description @@ -16,16 +16,16 @@ by mapping AngularJS syntax to the equivalent Angular syntax. **See the Angular syntax in this **. ## Contents -This page covers: -* [Template basics](#template-basics) - binding and local variables. -* [Template directives](#template-directives) - built-in directives `ngIf` and `ngClass`. +* [Template basics](#template-basics)—binding and local variables. -* [Filters/pipes](#filters-pipes) - built-in *filters*, known as *pipes* in Angular. +* [Template directives](#template-directives)—built-in directives `ngIf` and `ngClass`. -* [Modules/controllers/components](#controllers-components) - *modules* in Angular are slightly different from *modules* in AngularJS, and *controllers* are *components* in Angular. +* [Filters/pipes](#filters-pipes)—built-in *filters*, known as *pipes* in Angular. -* [Style sheets](#style-sheets) - more options for CSS than in AngularJS. +* [Modules/controllers/components](#controllers-components)—*modules* in Angular are slightly different from *modules* in AngularJS, and *controllers* are *components* in Angular. + +* [Style sheets](#style-sheets)—more options for CSS than in AngularJS. ## Template basics Templates are the user-facing part of an Angular application and are written in HTML. @@ -86,7 +86,8 @@ The following table lists some of the key AngularJS template features with their The context of the binding is implied and is always the associated component, so it needs no reference variable. - For more information, see the [Interpolation](../guide/template-syntax.html#interpolation) section of the Template Syntax page. + For more information, see the [Interpolation](../guide/template-syntax.html#interpolation) + section of the [Template Syntax](../guide/template-syntax.html) page. @@ -116,7 +117,7 @@ The following table lists some of the key AngularJS template features with their Many (but not all) of the built-in filters from AngularJS are built-in pipes in Angular. - For more information, see the heading [Filters/pipes](#filters-pipes) below. + For more information, see [Filters/pipes](#filters-pipes) below. @@ -144,7 +145,8 @@ The following table lists some of the key AngularJS template features with their Angular has true template input variables that are explicitly defined using the `let` keyword. - For more information, see the [ngFor micro-syntax](../guide/template-syntax.html#ngForMicrosyntax) section of the Template Syntax page. + For more information, see the [ngFor micro-syntax](../guide/template-syntax.html#microsyntax) + section of the [Template Syntax](../guide/template-syntax.html) page. @@ -260,7 +262,8 @@ The following are some of the key AngularJS built-in directives and their equiva Angular 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 the [Attribute, Class, and Style Bindings](../guide/template-syntax.html#other-bindings) section of the Template Syntax page. + For more information see the [Attribute, class, and style bindings](../guide/template-syntax.html#other-bindings) + section of the [Template Syntax](../guide/template-syntax.html) page. @@ -287,7 +290,7 @@ The following are some of the key AngularJS built-in directives and their equiva - ### bind to the `click` event + ### Bind to the `click` event {@example 'cb-ajs-quick-reference/ts/src/app/app.component.html' region='event-binding'} @@ -306,7 +309,8 @@ The following are some of the key AngularJS built-in directives and their equiva For a list of DOM events, see: https://developer.mozilla.org/en-US/docs/Web/Events. - For more information, see the [Event Binding](../guide/template-syntax.html#event-binding) section of the Template Syntax page. + For more information, see the [Event binding](../guide/template-syntax.html#event-binding) + section of the [Template Syntax](../guide/template-syntax.html) page. @@ -354,7 +358,7 @@ The following are some of the key AngularJS built-in directives and their equiva - ### bind to the `hidden` property + ### Bind to the `hidden` property In Angular, you use property binding; there is no built-in *hide* directive. For more information, see [ng-show](#ng-show). @@ -385,20 +389,22 @@ The following are some of the key AngularJS built-in directives and their equiva - ### bind to the `href` property + ### Bind to the `href` property {@example 'cb-ajs-quick-reference/ts/src/app/app.component.html' region='href'} - Angular, uses property binding; there is no built-in *href* directive. + Angular 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 see the [Property binding](../guide/template-syntax.html#property-binding) + section of the [Template Syntax](../guide/template-syntax.html) page. - In Angular, `href` is no longer used for routing. Routing uses `routerLink`, as shown in the third example. + In Angular, `href` is no longer used for routing. Routing uses `routerLink`, as shown in the following example. {@example 'cb-ajs-quick-reference/ts/src/app/app.component.html' region='router-link'} - For more information on routing, see [Routing & Navigation](../guide/router.html#router-link). + For more information on routing, see the [RouterLink binding](../guide/router.html#router-link) + section of the [Routing & Navigation](../guide/router.html) page. @@ -417,7 +423,7 @@ The following are some of the key AngularJS built-in directives and their equiva In AngularJS, 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. + In this example, the `` element is removed from the DOM unless the `movies` array has a length greater than zero. @@ -426,9 +432,10 @@ The following are some of the key AngularJS built-in directives and their equiva {@example 'cb-ajs-quick-reference/ts/src/app/movie-list.component.html' region='ngIf'} - The `*ngIf` directive in Angular works the same as the `ng-if` directive in AngularJS. It removes or recreates a portion of the DOM based on an expression. + The `*ngIf` directive in Angular works the same as the `ng-if` directive in AngularJS. 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. + In this example, the `
` 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). @@ -459,7 +466,9 @@ The following are some of the key AngularJS built-in directives and their equiva In Angular, **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 the [NgModel—Two-way binding to + form elements with `[(ngModel)]`](../guide/template-syntax.html#ngModel) + section of the [Template Syntax](../guide/template-syntax.html) page. @@ -477,7 +486,7 @@ The following are some of the key AngularJS built-in directives and their equiva In AngularJS, the `ng-repeat` directive repeats the associated DOM element for each item in the specified collection. - In this example, the table row (`tr`) element repeats for each movie object in the collection of movies. + In this example, the table row (``) element repeats for each movie object in the collection of movies. @@ -486,8 +495,9 @@ The following are some of the key AngularJS built-in directives and their equiva {@example 'cb-ajs-quick-reference/ts/src/app/movie-list.component.html' region='ngFor'} - The `*ngFor` directive in Angular is similar to the `ng-repeat` directive in AngularJS. 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 + The `*ngFor` directive in Angular is similar to the `ng-repeat` directive in AngularJS. It repeats + the associated DOM element for each item in the specified collection. + More accurately, it turns the defined element (`` in this example) and its contents into a template and uses that template to instantiate a view for each item in the list. Notice the other syntax differences: @@ -515,24 +525,25 @@ The following are some of the key AngularJS built-in directives and their equiva In AngularJS, 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. + In this example, the `
` element is shown if the `favoriteHero` variable is truthy.
@@ -554,14 +565,15 @@ The following are some of the key AngularJS built-in directives and their equiva @@ -578,7 +590,7 @@ The following are some of the key AngularJS built-in directives and their equiva In AngularJS, the `ng-style` directive sets a CSS style on an HTML element based on an expression. That expression is often a key-value control object with each - key of the object defined as a CSS style name, and each value defined as an expression + key of the object defined as a CSS property, and each value defined as an expression that evaluates to a value appropriate for the style. In the example, the `color` style is set to the current value of the `colorPreference` variable. @@ -596,9 +608,11 @@ The following are some of the key AngularJS built-in directives and their equiva Angular 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 the [Style binding](../guide/template-syntax.html#style-binding) section of the + [Template Syntax](../guide/template-syntax.html) page. - For more information on the ngStyle directive, see [Template Syntax](../guide/template-syntax.html#ngStyle). + For more information on the `ngStyle` directive, see [NgStyle](../guide/template-syntax.html#ngStyle) + section of the [Template Syntax](../guide/template-syntax.html) page. @@ -650,7 +664,8 @@ The following are some of the key AngularJS built-in directives and their equiva 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, see [The NgSwitch directives](../guide/template-syntax.html#ngSwitch) + section of the [Template Syntax](../guide/template-syntax.html) page. @@ -665,7 +680,7 @@ The following are some of the key AngularJS built-in directives and their equiva {@a filters-pipes} ## Filters/pipes -Angular **pipes** provide formatting and transformation for data in our template, similar to AngularJS **filters**. +Angular **pipes** provide formatting and transformation for data in the template, similar to AngularJS **filters**. Many of the built-in filters in AngularJS have corresponding pipes in Angular. For more information on pipes, see [Pipes](../guide/pipes.html). @@ -704,7 +719,7 @@ For more information on pipes, see [Pipes](../guide/pipes.html). <td>{{movie.price | currency}}</td> - Formats a number as a currency. + Formats a number as currency. @@ -949,17 +964,19 @@ The Angular code is shown using TypeScript. }()); - In AngularJS, you often defined an immediately invoked function expression (or IIFE) around your controller code. - This kept your controller code out of the global namespace. + In AngularJS, an immediately invoked function expression (or IIFE) around controller code + keeps it out of the global namespace. + @@ -974,7 +991,8 @@ The Angular code is shown using TypeScript. angular.module("movieHunter", ["ngRoute"]); - In AngularJS, 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. + In AngularJS, 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. @@ -987,7 +1005,7 @@ The Angular code is shown using TypeScript. - `imports`: specifies the list of other modules that this module depends upon - `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 (NgModule)](../guide/ngmodule.html). @@ -1006,7 +1024,7 @@ The Angular code is shown using TypeScript. MovieListCtrl]); - AngularJS, has code in each controller that looks up an appropriate Angular module + AngularJS 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 @@ -1015,17 +1033,18 @@ The Angular code is shown using TypeScript. @@ -1054,7 +1073,8 @@ The Angular code is shown using TypeScript. NOTE: If you are using TypeScript with AngularJS, you must use the `export` keyword to export the component class. - For more information, see the [Components](../guide/architecture.html#components) section of the Architecture Overview page. + For more information, see the [Components](../guide/architecture.html#components) + section of the [Architecture Overview](../guide/architecture.html) page. @@ -1088,7 +1108,8 @@ The Angular code is shown using TypeScript. This example injects a `MovieService`. The first parameter's TypeScript type tells Angular what to inject, even after minification. - For more information, see the [Dependency Injection](../guide/architecture.html#dependency-injection) section of the Architecture Overview. + For more information, see the [Dependency injection](../guide/architecture.html#dependency-injection) + section of the [Architecture Overview](../guide/architecture.html). diff --git a/aio/content/cookbook/aot-compiler.md b/aio/content/cookbook/aot-compiler.md index 7e0c28adc8..2e7c335167 100644 --- a/aio/content/cookbook/aot-compiler.md +++ b/aio/content/cookbook/aot-compiler.md @@ -615,9 +615,9 @@ The `source-map-explorer` analyzes the source map generated with the bundle and showing exactly which application and Angular modules and classes are included in the bundle. Here's the map for _Tour of Heroes_. - +
- TOH-6-bundle + TOH-6-bundle
\ No newline at end of file diff --git a/aio/content/cookbook/component-communication.md b/aio/content/cookbook/component-communication.md index f21ab84614..4fd6c0a95d 100644 --- a/aio/content/cookbook/component-communication.md +++ b/aio/content/cookbook/component-communication.md @@ -44,7 +44,7 @@ and each iteration's `hero` instance to the child's `hero` property. The running application displays three heroes:
- Parent-to-child + Parent-to-child
### Test it @@ -73,7 +73,7 @@ Here's the `NameParentComponent` demonstrating name variations including a name
- Parent-to-child-setter + Parent-to-child-setter
### Test it @@ -103,7 +103,7 @@ The `VersionParentComponent` supplies the `minor` and `major` values and binds b Here's the output of a button-pushing sequence:
- Parent-to-child-onchanges + Parent-to-child-onchanges
### Test it @@ -140,7 +140,7 @@ The framework passes the event argument — represented by `$event` — and the method processes it:
- Child-to-parent + Child-to-parent
### Test it @@ -185,7 +185,7 @@ use interpolation to display the child's `seconds` property. Here we see the parent and child working together.
- countdown timer + countdown timer
@@ -287,7 +287,7 @@ the parent `MissionControlComponent` and the `AstronautComponent` children, facilitated by the service:
- bidirectional-service + bidirectional-service
### Test it diff --git a/aio/content/cookbook/dependency-injection.md b/aio/content/cookbook/dependency-injection.md index 694f3ff44b..027395b594 100644 --- a/aio/content/cookbook/dependency-injection.md +++ b/aio/content/cookbook/dependency-injection.md @@ -122,7 +122,7 @@ The author simply declared what was needed in the constructor (`LoggerService` a Once all the dependencies are in place, the `AppComponent` displays the user information:
- Logged In User + Logged In User
### *@Injectable()* @@ -233,7 +233,7 @@ And the template displays this data-bound property. Find this example in live code and confirm that the three `HeroBioComponent` instances have their own cached hero data.
- Bios + Bios
@@ -280,7 +280,7 @@ placing it in the `` slot of the `HeroBioComponent` template: It looks like this, with the hero's telephone number from `HeroContactComponent` projected above the hero description:
- bio and contact + bio and contact
Here's the `HeroContactComponent` which demonstrates the qualifying decorators that we're talking about in this section: @@ -304,14 +304,14 @@ Thanks to `@Optional()`, Angular sets the `loggerService` to null and the rest o We'll come back to the `elementRef` property shortly.Here's the `HeroBiosAndContactsComponent` in action.
- Bios with contact into + Bios with contact into
If we comment out the `@Host()` decorator, Angular now walks up the injector ancestor tree until it finds the logger at the `AppComponent` level. The logger logic kicks in and the hero display updates with the gratuitous "!!!", indicating that the logger was found.
- Without @Host + Without @Host
On the other hand, if we restore the `@Host()` decorator and comment out `@Optional`, @@ -343,7 +343,7 @@ first without a value (yielding the default color) and then with an assigned col The following image shows the effect of mousing over the `` tag.
- Highlighted bios + Highlighted bios
@@ -394,7 +394,7 @@ We need other ways to deliver dependency values and that means we need other way The `HeroOfTheMonthComponent` example demonstrates many of the alternatives and why we need them.
- Hero of the month + Hero of the month
It's visually simple: a few properties and the output of a logger. The code behind it gives us plenty to talk about. @@ -493,14 +493,14 @@ We want to shrink that API surface to just the two members exposed by the `Minim The constructor's `logger` parameter is typed as `MinimalLogger` so only its two members are visible in TypeScript:
- MinimalLogger restricted API + MinimalLogger restricted API
Angular actually sets the `logger` parameter to the injector's full version of the `LoggerService` which happens to be the `DateLoggerService` thanks to the override provider registered previously via `useClass`. The following image, which displays the logging date, confirms the point:
- DateLoggerService entry + DateLoggerService entry
@@ -641,7 +641,7 @@ In this contrived example, `SortedHeroesComponent` inherits from `HeroesBaseComp to display a *sorted* list of heroes.
- Sorted Heroes + Sorted Heroes
The `HeroesBaseComponent` could stand on its own. @@ -783,7 +783,7 @@ The [*forwardRef*](#forwardref) breaks the circular reference we just created by Here's *Alex* and family in action:
- Alex in action + Alex in action
@@ -834,7 +834,7 @@ which *is* what parent means. Here's *Alice*, *Barry* and family in action:
- Alice in action + Alice in action
diff --git a/aio/content/cookbook/dynamic-component-loader.md b/aio/content/cookbook/dynamic-component-loader.md index f7524fc887..c232412f91 100644 --- a/aio/content/cookbook/dynamic-component-loader.md +++ b/aio/content/cookbook/dynamic-component-loader.md @@ -133,6 +133,6 @@ Two sample components and the `AdComponent` interface are shown below: The final ad banner looks like this:
- Ads + Ads
diff --git a/aio/content/cookbook/dynamic-form.md b/aio/content/cookbook/dynamic-form.md index a66e732e85..0ca0e144d1 100644 --- a/aio/content/cookbook/dynamic-form.md +++ b/aio/content/cookbook/dynamic-form.md @@ -162,7 +162,7 @@ This proves that any user input is bound back to the data model. Saving and retrieving the data is an exercise for another time. The final form looks like this:
- Dynamic-Form + Dynamic-Form
[Back to top](#top) \ No newline at end of file diff --git a/aio/content/cookbook/set-document-title.md b/aio/content/cookbook/set-document-title.md index 8ee9fb536d..b9a34e5078 100644 --- a/aio/content/cookbook/set-document-title.md +++ b/aio/content/cookbook/set-document-title.md @@ -23,7 +23,7 @@ This cookbook explains how to do it.**See the

pop out the window + pop out the window

pop out the window @@ -64,7 +64,7 @@ Let's inject the `Title` service into the root `AppComponent` and expose a binda We bind that method to three anchor tags and, voilà!
- Set title + Set title
Here's the complete solution diff --git a/aio/content/guide/animations.md b/aio/content/guide/animations.md index 4046caadc3..36cf753423 100644 --- a/aio/content/guide/animations.md +++ b/aio/content/guide/animations.md @@ -48,7 +48,7 @@ The examples in this page are available as a . ## Quickstart example: Transitioning between two states
- A simple transition animation + A simple transition animation
You can build a simple animation that transitions an element between two states @@ -121,7 +121,7 @@ controls the timing of switching between one set of styles and the next:
- In Angular animations you define states and transitions between states + In Angular animations you define states and transitions between states
If several transitions have the same timing configuration, you can combine @@ -154,7 +154,7 @@ transitions that apply regardless of which state the animation is in. For exampl * The `* => *` transition applies when *any* change between two states takes place.
- The wildcard state can be used to match many different transitions at once + The wildcard state can be used to match many different transitions at once
### The `void` state @@ -168,14 +168,14 @@ For example the `* => void` transition applies when the element leaves the view, regardless of what state it was in before it left.
- The void state can be used for enter and leave transitions + The void state can be used for enter and leave transitions
The wildcard state `*` also matches `void`. ## Example: Entering and leaving
- Enter and leave animations + Enter and leave animations
Using the `void` and `*` states you can define transitions that animate the @@ -184,6 +184,8 @@ entering and leaving of elements: * Enter: `void => *` * Leave: `* => void` +For example, in the `animations` !{_array} below there are two transitions that use +the `void => *` and `* => void` syntax to animate the element in and out of the view. {@example 'animations/ts/src/app/hero-list-enter-leave.component.ts' region='animationdef'} @@ -201,7 +203,7 @@ These two common animations have their own aliases: ## Example: Entering and leaving from different states
- Enter and leave animations combined with state animations + Enter and leave animations combined with state animations
You can also combine this animation with the earlier state transition animation by @@ -217,7 +219,7 @@ is: This gives you fine-grained control over each transition:
- This example transitions between active, inactive, and void states + This example transitions between active, inactive, and void states
@@ -245,7 +247,7 @@ If you don't provide a unit when specifying dimension, Angular assumes the defau ## Automatic property calculation
- Animation with automated height calculation + Animation with automated height calculation
Sometimes you don't know the value of a dimensional style property until runtime. @@ -297,21 +299,22 @@ and the delay (or as the *second* value when there is no delay): * Run for 200ms, with easing: `'0.2s ease-in-out'`
- Animations with specific timings + Animations with specific timings
### Example Here are a couple of custom timings in action. Both enter and leave last for -200 milliseconds but they have different easings. The leave begins after a -slight delay: +200 milliseconds, that is `0.2s`, but they have different easings. The leave begins after a +slight delay of 10 milliseconds as specified in `'0.2s 10 ease-out'`: + {@example 'animations/ts/src/app/hero-list-timings.component.ts' region='animationdef'} ## Multi-step animations with keyframes
- Animations with some bounce implemented with keyframes + Animations with some bounce implemented with keyframes
Animation *keyframes* go beyond a simple transition to a more intricate animation @@ -336,7 +339,7 @@ spacing are automatically assigned. For example, three keyframes without predefi offsets receive offsets `0`, `0.5`, and `1`. ## Parallel animation groups
- Parallel animations with different timings, implemented with groups + Parallel animations with different timings, implemented with groups
You've seen how to animate multiple style properties at the same time: @@ -358,7 +361,7 @@ One group animates the element transform and width; the other group animates the A callback is fired when an animation is started and also when it is done. -In the keyframes example, you have a `trigger` called `@flyInOut`. There you can hook +In the keyframes example, you have a `trigger` called `@flyInOut`. You can hook those callbacks like this: diff --git a/aio/content/guide/appmodule.md b/aio/content/guide/appmodule.md index f42b13c30a..10d3241be1 100644 --- a/aio/content/guide/appmodule.md +++ b/aio/content/guide/appmodule.md @@ -151,7 +151,7 @@ This file is very stable. Once you've set it up, you may never change it again. Your initial app has only a single module, the _root_ module. As your app grows, you'll consider subdividing it into multiple "feature" modules, -so of which can be loaded later ("lazy loaded") if and when the user chooses +some of which can be loaded later ("lazy loaded") if and when the user chooses to visit those features. When you're ready to explore these possibilities, visit the [Angular Modules (NgModule)](ngmodule.html) guide. \ No newline at end of file diff --git a/aio/content/guide/architecture.md b/aio/content/guide/architecture.md index de9ffb13ee..bf8972b46c 100644 --- a/aio/content/guide/architecture.md +++ b/aio/content/guide/architecture.md @@ -17,7 +17,7 @@ Of course, there is more to it than this. You'll learn the details in the pages that follow. For now, focus on the big picture.
- overview + overview
The architecture diagram identifies the eight main building blocks of an Angular application: @@ -41,13 +41,13 @@ Learn these building blocks, and you're on your way. ## Modules
- Component + Component
### Angular libraries
- Component + Component
@@ -59,7 +59,7 @@ Learn these building blocks, and you're on your way. ## Components
- Component + Component
A _component_ controls a patch of screen called a *view*. @@ -87,7 +87,7 @@ Your app can take action at each moment in this lifecycle through optional [life ## Templates
- Template + Template
You define a component's view with its companion **template**. A template is a form of HTML @@ -110,7 +110,7 @@ hero that the user selects from the list presented by the `HeroListComponent`. The `HeroDetailComponent` is a **child** of the `HeroListComponent`.
- Metadata + Metadata
Notice how `` rests comfortably among native HTML elements. Custom components mix seamlessly with native HTML in the same layouts. @@ -122,7 +122,7 @@ Notice how `` rests comfortably among native HTML elements. Custom ## Metadata
- Metadata + Metadata

Metadata tells Angular how to process a class.

@@ -150,7 +150,7 @@ This is one way to tell Angular that the component's constructor requires a `Her so it can get the list of heroes to display.
- Metadata + Metadata
The metadata in the `@Component` tells Angular where to get the major building blocks you specify for the component. @@ -171,7 +171,7 @@ Without a framework, you would be responsible for pushing data values into the H into actions and value updates. Writing such push/pull logic by hand is tedious, error-prone, and a nightmare to read as any experienced jQuery programmer can attest.
- Data Binding + Data Binding
Angular supports **data binding**, @@ -198,13 +198,13 @@ Angular processes *all* data bindings once per JavaScript event cycle, from the root of the application component tree through all child components.
- Data Binding + Data Binding
Data binding plays an important role in communication between a template and its component.
- Parent/Child binding + Parent/Child binding
Data binding is also important for communication between parent and child components.
@@ -215,7 +215,7 @@ Data binding is also important for communication between parent and child compon ## Directives
- Parent child + Parent child
Angular templates are *dynamic*. When Angular renders them, it transforms the DOM @@ -260,7 +260,7 @@ Of course, you can also write your own directives. Components such as ## Services
- Service + Service
_Service_ is a broad category encompassing any value, function, or feature that your application needs. @@ -305,7 +305,7 @@ application logic into services and make those services available to components ## Dependency injection
- Service + Service
_Dependency injection_ is a way to supply a new instance of a class @@ -324,7 +324,7 @@ This is *dependency injection*. The process of `HeroService` injection looks a bit like this:
- Service + Service
If the injector doesn't have a `HeroService`, how does it know how to make one? diff --git a/aio/content/guide/attribute-directives.md b/aio/content/guide/attribute-directives.md index 25c9a62e0f..b8a8df72d0 100644 --- a/aio/content/guide/attribute-directives.md +++ b/aio/content/guide/attribute-directives.md @@ -117,7 +117,7 @@ recognizes the directive when it encounters `myHighlight` in the template. Now when the app runs, the `myHighlight` directive highlights the paragraph text.
- First Highlight + First Highlight
@@ -180,7 +180,7 @@ Here's the updated directive in full: Run the app and confirm that the background color appears when the mouse hovers over the `p` and disappears as it moves out.
- Second Highlight + Second Highlight
@@ -260,7 +260,7 @@ lets you pick the highlight color with a radio button and bind your color choice Update `app.component.html` as follows: Revise the `AppComponent.color` so that it has no initial value.Here is the harness and directive in action.
- Highlight v.2 + Highlight v.2
@@ -292,7 +292,7 @@ because you made it _public_ with the `@Input` !{_decorator}. Here's how the harness should work when you're done coding.
- Final Highlight + Final Highlight
diff --git a/aio/content/guide/change-log.md b/aio/content/guide/change-log.md index 1fc50ab574..a4beeaf54e 100644 --- a/aio/content/guide/change-log.md +++ b/aio/content/guide/change-log.md @@ -8,6 +8,10 @@ An annotated history of recent documentation improvements. The Angular documentation is a living document with continuous improvements. This log calls attention to recent significant changes. +## NEW: Downloadable examples for each guide (2017-02-28) +Now you can download the sample code for any guide and run it locally. +Look for the new download links next to the "live example" links. + ## Template Syntax/Structural Directives: refreshed (2017-02-06) The [_Template-Syntax_](template-syntax.html) and [_Structural Directives_](structural-directives.html) guides were significantly revised for clarity, accuracy, and current recommended practices. diff --git a/aio/content/guide/component-styles.md b/aio/content/guide/component-styles.md index fa0063e9f5..aee0d4a2de 100644 --- a/aio/content/guide/component-styles.md +++ b/aio/content/guide/component-styles.md @@ -5,100 +5,96 @@ Component Styles Learn how to apply CSS styles to components. @description -Angular applications are styled with regular CSS. That means we can apply -everything we know about CSS stylesheets, selectors, rules, and media queries -to our Angular applications directly. +Angular applications are styled with standard CSS. That means you can apply +everything you know about CSS stylesheets, selectors, rules, and media queries +directly to Angular applications. -On top of this, Angular has the ability to bundle *component styles* -with our components enabling a more modular design than regular stylesheets. +Additionally, Angular can bundle *component styles* +with components, enabling a more modular design than regular stylesheets. -In this chapter we learn how to load and apply these *component styles*. +This page describes how to load and apply these component styles. ## Table Of Contents -* [Using Component Styles](#using-component-styles) +* [Using component styles](#using-component-styles) * [Special selectors](#special-selectors) -* [Loading Styles into Components](#loading-styles) -* [Controlling View Encapsulation: Emulated, Native, and None](#view-encapsulation) -* [Appendix 1: Inspecting the generated runtime component styles](#inspect-generated-css) -* [Appendix 2: Loading Styles with Relative URLs](#relative-urls) +* [Loading styles into components](#loading-styles) +* [Controlling view encapsulation: native, emulated, and none](#view-encapsulation) +* [Appendix 1: Inspecting the CSS generated in emulated view encapsulation](#inspect-generated-css) +* [Appendix 2: Loading styles with relative URLs](#relative-urls) -Run the of the code shown in this chapter. +You can run the in Plunker and download the code from there. -## Using Component Styles +## Using component styles -For every Angular component we write, we may define not only an HTML template, +For every Angular component you write, you may define not only an HTML template, but also the CSS styles that go with that template, -specifying any selectors, rules, and media queries that we need. +specifying any selectors, rules, and media queries that you need. One way to do this is to set the `styles` property in the component metadata. The `styles` property takes #{_an} #{_array} of strings that contain CSS code. -Usually we give it one string as in this example: +Usually you give it one string, as in the following example: {@example 'component-styles/ts/src/app/hero-app.component.ts'} -Component styles differ from traditional, global styles in a couple of ways. - -Firstly, the selectors we put into a component's styles *only apply within the template -of that component*. The `h1` selector in the example above only applies to the `

` tag +The selectors you put into a component's styles apply only within the template +of that component. The `h1` selector in the preceding example applies only to the `

` tag in the template of `HeroAppComponent`. Any `

` elements elsewhere in the application are unaffected. -This is a big improvement in modularity compared to how CSS traditionally works: +This is a big improvement in modularity compared to how CSS traditionally works. -1. We can use the CSS class names and selectors that make the most sense in the context of each component. - -1. Class names and selectors are local to the component and won't collide with -classes and selectors used elsewhere in the application. - -1. Our component's styles *cannot* be changed by changes to styles elsewhere in the application. - -1. We can co-locate the CSS code of each component with the TypeScript and HTML code of the component, - which leads to a neat and tidy project structure. - -1. We can change or remove component CSS code in the future without trawling through the - whole application to see where else it may have been used. We just look at the component we're in. +* You can use the CSS class names and selectors that make the most sense in the context of each component. +* Class names and selectors are local to the component and don't collide with + classes and selectors used elsewhere in the application. +* Changes to styles elsewhere in the application don't affect the component's styles. +* You can co-locate the CSS code of each component with the TypeScript and HTML code of the component, + which leads to a neat and tidy project structure. +* You can change or remove component CSS code without searching through the + whole application to find where else the code is used. {@a special-selectors} ## Special selectors -Component styles have a few special *selectors* from the world of -[shadow DOM style scoping](https://www.w3.org/TR/css-scoping-1): +Component styles have a few special *selectors* from the world of shadow DOM style scoping +(described in the [CSS Scoping Module Level 1](https://www.w3.org/TR/css-scoping-1) page on the +[W3C](https://www.w3.org) site). +The following sections describe these selectors. ### :host Use the `:host` pseudo-class selector to target styles in the element that *hosts* the component (as opposed to -targeting elements *inside* the component's template): +targeting elements *inside* the component's template). {@example 'component-styles/ts/src/app/hero-details.component.css' region='host'} -This is the *only* way we can target the host element. We cannot reach -it from inside the component with other selectors, because it is not part of the -component's own template. It is in a parent component's template. +The `:host` selector is the only way to target the host element. You can't reach +the host element from inside the component with other selectors because it's not part of the +component's own template. The host element is in a parent component's template. Use the *function form* to apply host styles conditionally by including another selector inside parentheses after `:host`. -In the next example we target the host element again, but only when it also has the `active` CSS class. +The next example targets the host element again, but only when it also has the `active` CSS class. {@example 'component-styles/ts/src/app/hero-details.component.css' region='hostfunction'} ### :host-context -Sometimes it is useful to apply styles based on some condition *outside* a component's view. -For example, there may be a CSS theme class applied to the document `` element, and -we want to change how our component looks based on that. +Sometimes it's useful to apply styles based on some condition *outside* of a component's view. +For example, a CSS theme class could be applied to the document `` element, and +you want to change how your component looks based on that. -Use the `:host-context()` pseudo-class selector. It works just like the function -form of `:host()`. It looks for a CSS class in *any ancestor* of the component host element, all the way -up to the document root. It's useful when combined with another selector. +Use the `:host-context()` pseudo-class selector, which works just like the function +form of `:host()`. The `:host-context()` selector looks for a CSS class in any ancestor of the component host element, +up to the document root. The `:host-context()` selector is useful when combined with another selector. -In the following example, we apply a `background-color` style to all `

` elements *inside* the component, only +The following example applies a `background-color` style to all `

` elements *inside* the component, only if some ancestor element has the CSS class `theme-light`. @@ -108,24 +104,23 @@ if some ancestor element has the CSS class `theme-light`. Component styles normally apply only to the HTML in the component's own template. -We can use the `/deep/` selector to force a style down through the child component tree into all the child component views. -The `/deep/` selector works to any depth of nested components, and it applies *both to the view -children and the content children* of the component. +Use the `/deep/` selector to force a style down through the child component tree into all the child component views. +The `/deep/` selector works to any depth of nested components, and it applies to both the view +children and content children of the component. -In this example, we target all `

` elements, from the host element down -through this component to all of its child elements in the DOM: +The following example targets all `

` elements, from the host element down +through this component to all of its child elements in the DOM. {@example 'component-styles/ts/src/app/hero-details.component.css' region='deep'} -The `/deep/` selector also has the alias `>>>`. We can use either of the two interchangeably. +The `/deep/` selector also has the alias `>>>`. You can use either interchangeably. ~~~ {.alert.is-important} -The `/deep/` and `>>>` selectors should only be used with **emulated** view encapsulation. -This is the default and it is what we use most of the time. See the -[Controlling View Encapsulation](#view-encapsulation) -section for more details. +Use the `/deep/` and `>>>` selectors only with *emulated* view encapsulation. +Emulated is the default and most commonly used view encapsulation. For more information, see the +[Controlling view encapsulation](#view-encapsulation) section. ~~~ @@ -134,53 +129,54 @@ section for more details. {@a loading-styles} -## Loading Styles into Components +## Loading styles into components -We have several ways to add styles to a component: -* inline in the template HTML -* by setting `styles` or `styleUrls` metadata -* with CSS imports +There are several ways to add styles to a component: +* By setting `styles` or `styleUrls` metadata. +* Inline in the template HTML. +* With CSS imports. -The scoping rules outlined above apply to each of these loading patterns. +The scoping rules outlined earlier apply to each of these loading patterns. -### Styles in Metadata +### Styles in metadata -We can add a `styles` #{_array} property to the `@Component` #{_decorator}. +You can add a `styles` #{_array} property to the `@Component` #{_decorator}. Each string in the #{_array} (usually just one string) defines the CSS. {@example 'component-styles/ts/src/app/hero-app.component.ts'} -### Template Inline Styles +### Style URLs in metadata -We can embed styles directly into the HTML template by putting them -inside `

- ### bind to the `hidden` property + ### Bind to the `hidden` property {@example 'cb-ajs-quick-reference/ts/src/app/movie-list.component.html' region='hidden'} - Angular, uses property binding; there is no built-in *show* directive. + Angular 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. + In this example, the `
` 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 the [Property binding](../guide/template-syntax.html#property-binding) + section of the [Template Syntax](../guide/template-syntax.html) page.
- ### bind to the `src` property + ### Bind to the `src` property {@example 'cb-ajs-quick-reference/ts/src/app/app.component.html' region='src'} - Angular, uses property binding; there is no built-in *src* directive. + Angular 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 the [Property binding](../guide/template-syntax.html#property-binding) + section of the [Template Syntax](../guide/template-syntax.html) page. ### none - You don't need to worry about this in Angular because you use ES 2015 modules - and modules handle the namespacing for you. + This is a nonissue in Angular because ES 2015 modules + handle the namespacing for you. - For more information on modules, see [Architecture Overview](../guide/architecture.html#module). + For more information on modules, see the [Modules](../guide/architecture.html#modules) section of the + [Architecture Overview](../guide/architecture.html). - ### Component Decorator + ### Component decorator {@example 'cb-ajs-quick-reference/ts/src/app/movie-list.component.ts' region='component'} - Angular, 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 + Angular 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. - This is how you associate a template with code, which is defined in the component class. + This is how you associate a template with logic, which is defined in the component class. - For more information, see the [Components](../guide/architecture.html#components) section of the Architecture Overview page. + For more information, see the [Components](../guide/architecture.html#components) + section of the [Architecture Overview](../guide/architecture.html) page.