@@ -64,7 +64,7 @@ a#write-directive
6464include ../_quickstart_repo
6565:marked
6666 Create the following source file in the indicated folder with the given code:
67- + makeExample('attribute-directives/ts/ app/highlight.directive.1.ts' , null , 'app/highlight.directive .ts' )
67+ + makeExample('app/highlight.directive.1.ts' )
6868
6969block highlight-directive-1
7070 :marked
@@ -97,7 +97,7 @@ block highlight-directive-1
9797
9898 We need a prefix of our own, preferably short, and `my` will do for now.
9999p
100- | After the ` @Directive` metadata comes the directive's controller class, which contains the logic for the directive.
100+ | After the #[ code @Directive] metadata comes the directive's controller class, which contains the logic for the directive.
101101 + ifDocsFor('ts' )
102102 | We export `HighlightDirective` to make it accessible to other components.
103103:marked
@@ -169,13 +169,13 @@ a#respond-to-user
169169 1. detect when the user hovers into and out of the element,
170170 2. respond to those actions by setting and clearing the highlight color, respectively.
171171
172- We use the `@HostListener` decorator on a method which is called when the event is raised.
172+ We apply the `@HostListener` !{_decorator} to methods which are called when an event is raised.
173173
174174+ makeExample('attribute-directives/ts/app/highlight.directive.2.ts' ,'host' )( format ="." )
175175
176176.l-sub-section
177177 :marked
178- The `@HostListener` decorator refers to the DOM element that hosts our attribute directive, the `<p>` in our case.
178+ The `@HostListener` !{_decorator} refers to the DOM element that hosts our attribute directive, the `<p>` in our case.
179179
180180 We could have attached event listeners by manipulating the host DOM element directly, but
181181 there are at least three problems with such an approach:
@@ -184,7 +184,7 @@ a#respond-to-user
184184 1. We must *detach* our listener when the directive is destroyed to avoid memory leaks.
185185 1. We'd be talking to DOM API directly which, we learned, is something to avoid.
186186
187- Let's roll with the `@HostListener` decorator .
187+ Let's roll with the `@HostListener` !{_decorator} .
188188:marked
189189 Now we implement the two mouse event handlers:
190190+ makeExample('attribute-directives/ts/app/highlight.directive.2.ts' ,'mouse-methods' )( format ="." )
@@ -195,7 +195,7 @@ a#respond-to-user
195195+ makeExample('attribute-directives/ts/app/highlight.directive.2.ts' ,'ctor' )( format ="." )
196196:marked
197197 Here's the updated directive:
198- + makeExample('attribute-directives/ts/ app/highlight.directive.2.ts' , null , 'app/highlight.directive .ts' )
198+ + makeExample('app/highlight.directive.2.ts' )
199199:marked
200200 We run the app and confirm that the background color appears as we move the mouse over the `p` and
201201 disappears as we move out.
@@ -213,12 +213,12 @@ a#bindings
213213 We'll extend our directive class with a bindable **input** `highlightColor` property and use it when we highlight text.
214214
215215 Here is the final version of the class:
216- + makeExample( 'attribute-directives/ts/ app/highlight.directive.ts' , 'class-1' , 'app/highlight.directive.ts (class only) ' )
216+ + makeExcerpt( ' app/highlight.directive.ts' , 'class' )
217217a#input
218218:marked
219219 The new `highlightColor` property is called an *input* property because data flows from the binding expression into our directive.
220220 Notice the `@Input()` #{_decorator} applied to the property.
221- + makeExample( 'attribute-directives/ts/ app/highlight.directive.ts' , 'color' )
221+ + makeExcerpt( ' app/highlight.directive.ts' , 'color' )
222222:marked
223223 `@Input` adds metadata to the class that makes the `highlightColor` property available for
224224 property binding under the `myHighlight` alias.
@@ -232,25 +232,25 @@ a#input
232232
233233 We could resolve the discrepancy by renaming the property to `myHighlight` and define it as follows:
234234
235- + makeExample( 'attribute-directives/ts/ app/highlight.directive.ts' , 'highlight' )
235+ + makeExcerpt( ' app/highlight.directive.ts' , 'highlight' , ' ' )
236236 :marked
237237 Maybe we don't want that property name inside the directive perhaps because it
238238 doesn't express our intention well.
239239 We can **alias** the `highlightColor` property with the attribute name by
240240 passing `myHighlight` into the `@Input` #{_decorator}:
241- + makeExample( 'attribute-directives/ts/ app/highlight.directive.ts' , 'color' )
241+ + makeExcerpt( ' app/highlight.directive.ts' , 'color' , ' ' )
242242:marked
243243 Now that we're getting the highlight color as an input, we modify the `onMouseEnter()` method to use
244244 it instead of the hard-coded color name.
245245 We also define red as the default color to fallback on in case
246246 the user neglects to bind with a color.
247- + makeExample ('attribute-directives/ts/app/highlight.directive.ts' , 'mouse-enter' )
247+ + makeExcerpt ('attribute-directives/ts/app/highlight.directive.ts' , 'mouse-enter' , ' ' )
248248:marked
249249 Now we'll update our `AppComponent` template to let
250250 users pick the highlight color and bind their choice to our directive.
251251
252252 Here is the updated template:
253- + makeExample ('attribute-directives/ts/app/app.component.html' , 'v2' )
253+ + makeExcerpt ('attribute-directives/ts/app/app.component.html' , 'v2' , ' ' )
254254
255255.l-sub-section
256256 :marked
0 commit comments