diff --git a/aio/content/examples/pipes/e2e/src/app.e2e-spec.ts b/aio/content/examples/pipes/e2e/src/app.e2e-spec.ts index cabb8f0baa..35ce8776b0 100644 --- a/aio/content/examples/pipes/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/pipes/e2e/src/app.e2e-spec.ts @@ -102,7 +102,7 @@ describe('Pipes', () => { }); it('should show an async hero message', async () => { - expect(await element.all(by.tagName('app-hero-message')).get(0).getText()).toContain('hero'); + expect(await element.all(by.tagName('app-hero-async-message')).get(0).getText()).toContain('hero'); }); }); diff --git a/aio/content/examples/pipes/src/app/app.component.html b/aio/content/examples/pipes/src/app/app.component.html index c443e5a21e..0921236076 100644 --- a/aio/content/examples/pipes/src/app/app.component.html +++ b/aio/content/examples/pipes/src/app/app.component.html @@ -1,16 +1,16 @@

Pipes

-Happy Birthday v1
-Birthday DatePipe
-Happy Birthday v2
-Birthday Pipe Chaining
-Power Booster custom pipe
-Power Boost Calculator custom pipe with params
-Flying Heroes filter pipe (pure)
-Flying Heroes filter pipe (impure)
-Async Hero Message and AsyncPipe
-Hero List with caching FetchJsonPipe
-Pipes and Precedence
+Happy Birthday v1 +Birthday DatePipe +Happy Birthday v2 +Birthday Pipe Chaining +Power Booster custom pipe +Power Boost Calculator custom pipe with params +Flying Heroes filter pipe (pure) +Flying Heroes filter pipe (impure) +Async Hero Message and AsyncPipe +Hero List with caching FetchJsonPipe +Pipes and Precedence
@@ -73,7 +73,7 @@
- +
diff --git a/aio/content/examples/pipes/src/app/app.component.ts b/aio/content/examples/pipes/src/app/app.component.ts index 5b71cc53c7..aa1be493c9 100644 --- a/aio/content/examples/pipes/src/app/app.component.ts +++ b/aio/content/examples/pipes/src/app/app.component.ts @@ -3,7 +3,8 @@ import { Component } from '@angular/core'; @Component({ selector: 'app-root', - templateUrl: './app.component.html' + templateUrl: './app.component.html', + styles: ['a[href] {display: block; padding: 10px 0;}', 'a:hover {text-decoration: none;}', 'h2 {margin: 0;}'] }) export class AppComponent { birthday = new Date(1988, 3, 15); // April 15, 1988 -- since month parameter is zero-based diff --git a/aio/content/examples/pipes/src/app/flying-heroes-impure.component.html b/aio/content/examples/pipes/src/app/flying-heroes-impure.component.html index 8a7089aaf8..7793c1d7f7 100644 --- a/aio/content/examples/pipes/src/app/flying-heroes-impure.component.html +++ b/aio/content/examples/pipes/src/app/flying-heroes-impure.component.html @@ -1,19 +1,24 @@

{{title}}

-

-New hero: - - can fly -

-

+ + + +

+ + +
+ +
Mutate array -

+
-

Heroes who fly (piped)

+

Heroes who fly (piped)

@@ -22,7 +27,7 @@ New hero:
-

All Heroes (no pipe)

+

All Heroes (no pipe)

{{hero.name}} diff --git a/aio/content/examples/pipes/src/app/flying-heroes.component.html b/aio/content/examples/pipes/src/app/flying-heroes.component.html index fe865acf2c..62b1cd1bab 100644 --- a/aio/content/examples/pipes/src/app/flying-heroes.component.html +++ b/aio/content/examples/pipes/src/app/flying-heroes.component.html @@ -1,23 +1,27 @@

{{title}}

-

+

Create a new hero and press enter to add it to the list.

-New hero: - + + - can fly -

-

- Mutate array +

+ + +
+
+ + - + -

+
-

Heroes who fly (piped)

+

Heroes who fly (piped)

@@ -26,7 +30,7 @@ New hero:
-

All Heroes (no pipe)

+

All Heroes (no pipe)

diff --git a/aio/content/examples/pipes/src/app/flying-heroes.component.ts b/aio/content/examples/pipes/src/app/flying-heroes.component.ts index f7253c48dc..5a27a930d0 100644 --- a/aio/content/examples/pipes/src/app/flying-heroes.component.ts +++ b/aio/content/examples/pipes/src/app/flying-heroes.component.ts @@ -7,7 +7,7 @@ import { HEROES } from './heroes'; @Component({ selector: 'app-flying-heroes', templateUrl: './flying-heroes.component.html', - styles: ['#flyers, #all {font-style: italic}'] + styles: ['#flyers, #all {font-style: italic}', 'button {display: block}', 'input {margin: .25rem .25rem .5rem 0;}'] }) // #docregion v1 export class FlyingHeroesComponent { @@ -48,7 +48,7 @@ export class FlyingHeroesComponent { @Component({ selector: 'app-flying-heroes-impure', templateUrl: './flying-heroes-impure.component.html', - styles: ['.flyers, .all {font-style: italic}'], + styles: ['#flyers, #all {font-style: italic}', 'button {display: block}', 'input {margin: .25rem .25rem .5rem 0;}'], }) export class FlyingHeroesImpureComponent extends FlyingHeroesComponent { title = 'Flying Heroes (impure pipe)'; diff --git a/aio/content/examples/pipes/src/app/hero-async-message.component.ts b/aio/content/examples/pipes/src/app/hero-async-message.component.ts index 7c922fbd35..8b5428a592 100644 --- a/aio/content/examples/pipes/src/app/hero-async-message.component.ts +++ b/aio/content/examples/pipes/src/app/hero-async-message.component.ts @@ -5,7 +5,7 @@ import { Observable, interval } from 'rxjs'; import { map, take } from 'rxjs/operators'; @Component({ - selector: 'app-hero-message', + selector: 'app-hero-async-message', template: `

Async Hero Message and AsyncPipe

Message: {{ message$ | async }}

diff --git a/aio/content/examples/pipes/src/app/power-boost-calculator.component.ts b/aio/content/examples/pipes/src/app/power-boost-calculator.component.ts index 5092e18893..b3a0a22920 100644 --- a/aio/content/examples/pipes/src/app/power-boost-calculator.component.ts +++ b/aio/content/examples/pipes/src/app/power-boost-calculator.component.ts @@ -5,12 +5,15 @@ import { Component } from '@angular/core'; selector: 'app-power-boost-calculator', template: `

Power Boost Calculator

-
Normal power:
-
Boost factor:
+ + + +

Super Hero Power: {{power | exponentialStrength: factor}}

- ` + `, + styles: ['input {margin: .5rem 0;}'] }) export class PowerBoostCalculatorComponent { power = 5; diff --git a/aio/content/examples/pipes/src/app/precedence.component.html b/aio/content/examples/pipes/src/app/precedence.component.html index 3b4a208e7e..bd0c468566 100644 --- a/aio/content/examples/pipes/src/app/precedence.component.html +++ b/aio/content/examples/pipes/src/app/precedence.component.html @@ -3,7 +3,7 @@

{{title}}

Basic uppercase pipe (no precedence considerations necessary): {{ 'text' | uppercase }}

-

The following shows that a pipe has higher precedence than a ternary operator. If the pipe precedence were lower than the ternary operator precedence, the output would be 'TRUE'. Instead it is: {{ true ? 'true' : 'false' | uppercase }}

+

The following shows that a pipe has higher precedence than a ternary operator. If the pipe precedence were lower than the ternary operator precedence, the output would be in uppercase as in 'TRUE'. Instead "true" is lowercase: {{ true ? 'true' : 'false' | uppercase }}

The following shows how parentheses help Angular evaluate the whole statement: diff --git a/aio/content/examples/pipes/src/app/precedence.component.ts b/aio/content/examples/pipes/src/app/precedence.component.ts index c4132c881f..e3afb1cc79 100644 --- a/aio/content/examples/pipes/src/app/precedence.component.ts +++ b/aio/content/examples/pipes/src/app/precedence.component.ts @@ -2,8 +2,7 @@ import { Component } from '@angular/core'; @Component({ selector: 'app-precedence', - templateUrl: './precedence.component.html', - styles: [] + templateUrl: './precedence.component.html' }) export class PrecedenceComponent { diff --git a/aio/content/guide/pipes.md b/aio/content/guide/pipes.md index a76c91b879..30332a3786 100644 --- a/aio/content/guide/pipes.md +++ b/aio/content/guide/pipes.md @@ -100,13 +100,7 @@ The tabs in the following example demonstrates toggling between two different fo -Clicking the **Toggle Format** button alternates the date format between **04/15/1988** and **Friday, April 15, 1988** as shown in Figure 1. - -

- -**Figure 1.** Clicking the button toggles the date format +Clicking the **Toggle Format** button alternates the date format between **04/15/1988** and **Friday, April 15, 1988**.
@@ -176,7 +170,6 @@ The following code example shows two component definitions: It defines an argument to the `transform` method (`exponent`) for a parameter passed to the pipe. * The `power-booster.component.ts` component demonstrates how to use the pipe, specifying a value (`2`) and the exponent parameter (`10`). -Figure 2 shows the output. - +The browser displays the following: -**Figure 2.** Output from the `exponentialStrength` pipe + + +Power Booster + +Superpower boost: 1024 + +
@@ -214,13 +211,7 @@ For example, you could change the previous custom pipe example to use two-way da -The `exponentialStrength` pipe executes every time the user changes the "normal power" value or the "boost factor", as shown in Figure 3. - - - -**Figure 3.** Changing the amount and boost factor for the `exponentialStrength` pipe +The `exponentialStrength` pipe executes every time the user changes the "normal power" value or the "boost factor". Angular detects each change and immediately runs the pipe. This is fine for primitive input values. @@ -306,17 +297,11 @@ You can replace the array with a new array containing the newly changed elements In the above example, you can create an array with the new hero appended, and assign that to `heroes`. Angular detects the change in the array reference and executes the pipe. To summarize, if you mutate the input array, the pure pipe doesn't execute. -If you *replace* the input array, the pipe executes and the display is updated, as shown in Figure 4. - - - -**Figure 4.** The `flyingHeroes` pipe filtering the display to flying heroes +If you *replace* the input array, the pipe executes and the display is updated. The above example demonstrates changing a component's code to accommodate a pipe. -To keep your component simpler and independent of HTML templates that use pipes, you can, as an alternative, use an *impure* pipe to detect changes within composite objects such as arrays, as described in the next section. +To keep your component independent of HTML templates that use pipes, you can, as an alternative, use an *impure* pipe to detect changes within composite objects such as arrays, as described in the next section. {@a impure-flying-heroes} @@ -423,13 +408,20 @@ In the above example, a breakpoint on the pipe's request for data shows the foll * Each binding gets its own pipe instance. * Each pipe instance caches its own URL and data and calls the server only once. -The `fetch` and `fetch-json` pipes display the heroes as shown in Figure 5. +The `fetch` and `fetch-json` pipes display the heroes in the browser as follows: - + -**Figure 5.** The `fetch` and `fetch-json` pipes displaying the heroes +Heroes from JSON File + +Windstorm +Bombasto +Magneto +Tornado + +Heroes as JSON: [ { "name": "Windstorm", "canFly": true }, { "name": "Bombasto", "canFly": false }, { "name": "Magneto", "canFly": false }, { "name": "Tornado", "canFly": true } ] + +
diff --git a/aio/content/images/guide/pipes/date-format-toggle-anim.gif b/aio/content/images/guide/pipes/date-format-toggle-anim.gif deleted file mode 100644 index 379c48df95..0000000000 Binary files a/aio/content/images/guide/pipes/date-format-toggle-anim.gif and /dev/null differ diff --git a/aio/content/images/guide/pipes/power-boost-calculator-anim.gif b/aio/content/images/guide/pipes/power-boost-calculator-anim.gif deleted file mode 100644 index 27ff25d115..0000000000 Binary files a/aio/content/images/guide/pipes/power-boost-calculator-anim.gif and /dev/null differ diff --git a/aio/content/images/guide/pipes/power-booster.png b/aio/content/images/guide/pipes/power-booster.png deleted file mode 100644 index 434e3db1b1..0000000000 Binary files a/aio/content/images/guide/pipes/power-booster.png and /dev/null differ