@@ -162,14 +162,16 @@ figure.image-display
162
162
figure.image-display
163
163
img( src ='/resources/images/devguide/pipes/power-booster.png' alt ="Power Booster" )
164
164
165
+ - var _decls = _docsFor == ' dart' ? ' pipes' : ' declarations' ;
166
+ - var _appMod = _docsFor == ' dart' ? ' @Component' : ' AppModule' ;
165
167
:marked
166
168
Two things to note:
167
- 1. We use our custom pipe the same way we use the built-in pipes.
168
169
169
- 1. We must include our pipe in the `pipes` #{_array} of the `@Component` #{_decorator}.
170
+ 1. We use our custom pipe the same way we use built-in pipes.
171
+ 1. We must include our pipe in the `!{_decls}` #{_array} of the `!{_appMod}`.
170
172
171
173
.callout.is-helpful
172
- header Remember the pipes #{_array} !
174
+ header Remember the !{_decls} #{_array} !
173
175
:marked
174
176
Angular reports an error if we neglect to list our custom pipe.
175
177
We didn't list the `DatePipe` in our previous example because all
@@ -186,7 +188,7 @@ figure.image-display
186
188
We could upgrade the example to a "Power Boost Calculator" that combines
187
189
our pipe and two-way data binding with `ngModel`.
188
190
189
- + makeExample('pipes/ts/ app/power-boost-calculator.component.ts' , null , '/app/power-boost-calculator.component.ts' ) ( format = '. ')
191
+ + makeExample('app/power-boost-calculator.component.ts' )
190
192
191
193
figure.image-display
192
194
img( src ='/resources/images/devguide/pipes/power-boost-calculator-anim.gif' alt ="Power Boost Calculator" )
@@ -331,10 +333,16 @@ block pure-change
331
333
The only difference is the `pure` flag in the pipe metadata.
332
334
333
335
This is a good candidate for an impure pipe because the `transform` function is trivial and fast.
334
- + makeExample('pipes/ts/app/flying-heroes.pipe.ts' ,'filter' )( format ='.' )
335
336
336
- We can derive a `FlyingHeroesImpureComponent` that we derive from the `FlyingHeroesComponent`.
337
- + makeExample('pipes/ts/app/flying-heroes.component.ts' ,'impure-component' ,'app/flying-heroes.component.ts (FlyingHeroesImpureComponent)' )( format ='.' )
337
+ + makeExcerpt('app/flying-heroes.pipe.ts' ,'filter' , '' )
338
+
339
+ :marked
340
+ We can derive a `FlyingHeroesImpureComponent` from `FlyingHeroesComponent`.
341
+
342
+ - var _fnSuffix = _docsFor == ' dart' ? ' .component.ts' : ' -impure.component.html' ;
343
+ - var _region = _docsFor == ' dart' ? ' impure-component' : ' template-flying-heroes' ;
344
+ + makeExcerpt('app/flying-heroes' + _fnSuffix + ' (excerpt)' , _region)
345
+
338
346
:marked
339
347
The only substantive change is the pipe in the template.
340
348
We can confirm in the <live-example></live-example> that the _flying heroes_
@@ -361,7 +369,7 @@ h3#async-pipe The impure #[i AsyncPipe]
361
369
The component doesn't have to subscribe to the async data source,
362
370
it doesn't extract the resolved values and expose them for binding,
363
371
and the component doesn't have to unsubscribe when it is destroyed
364
- (a potential source of memory leaks).
372
+ (a potent source of memory leaks).
365
373
366
374
### An impure caching pipe
367
375
@@ -372,14 +380,14 @@ h3#async-pipe The impure #[i AsyncPipe]
372
380
373
381
We are careful.
374
382
The pipe only calls the server when the request URL changes and it caches the server response.
375
- Here's the code, which uses the [Angular http](server-communication.html) client to retrieve data:
383
+ Here's the code<span if-docs="ts"> , which uses the [Angular http](server-communication.html) client to retrieve data</span> :
376
384
377
- + makeExample('pipes/ts/app/fetch-json.pipe.ts' , null , ' app/fetch-json.pipe.ts' )
385
+ + makeExample('app/fetch-json.pipe.ts' )
378
386
:marked
379
387
Then we demonstrate it in a harness component whose template defines two bindings to this pipe,
380
388
both requesting the heroes from the `heroes.json` file.
381
389
382
- + makeExample('pipes/ts/app/hero-list.component.ts' , null , ' app/hero-list.component.ts' )
390
+ + makeExample('app/hero-list.component.ts' )
383
391
:marked
384
392
The component renders like this:
385
393
@@ -392,7 +400,6 @@ figure.image-display
392
400
* each pipe instance caches its own url and data
393
401
* each pipe instance only calls the server once
394
402
395
- :marked
396
403
### *JsonPipe*
397
404
398
405
The second `fetch` pipe binding above demonstrates more pipe chaining.
@@ -404,8 +411,8 @@ figure.image-display
404
411
The [JsonPipe](../api/common/index/JsonPipe-pipe.html)
405
412
provides an easy way to diagnosis a mysteriously failing data binding or
406
413
inspect an object for future binding.
407
-
408
- a( id = " pure-pipe-pure-fn" )
414
+
415
+ a# pure-pipe-pure-fn
409
416
:marked
410
417
### Pure pipes and pure functions
411
418
0 commit comments