Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit dfd072f

Browse files
kapunahelewongwardbell
authored andcommitted
docs(attribute-directives): copy tweaks (#3284)
1 parent 894ff63 commit dfd072f

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

public/docs/_examples/attribute-directives/ts/src/app/app.component.1.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<!-- #docregion -->
22
<h1>My First Attribute Directive</h1>
3+
<!-- #docregion applied -->
34
<p myHighlight>Highlight me!</p>
5+
<!-- #enddocregion applied -->
46
<!-- #enddocregion -->
57

68
<!-- #docregion color-1 -->

public/docs/ts/latest/guide/attribute-directives.jade

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ a#directive-overview
2424
## Directives overview
2525

2626
There are three kinds of directives in Angular:
27-
28-
1. Components &mdash; directives with a template.
29-
1. Structural directives &mdash; change the DOM layout by adding and removing DOM elements.
30-
1. Attribute directives &mdash; change the appearance or behavior of an element, component, or another directive.
27+
28+
1. Components&mdash;directives with a template.
29+
1. Structural directives&mdash;change the DOM layout by adding and removing DOM elements.
30+
1. Attribute directives&mdash;change the appearance or behavior of an element, component, or another directive.
3131

3232
*Components* are the most common of the three directives.
33-
You saw a component for the first time in the [QuickStart](../quickstart.html) example.
33+
You saw a component for the first time in the [QuickStart](../quickstart.html) guide.
3434

3535
*Structural Directives* change the structure of the view.
3636
Two examples are [NgFor](template-syntax.html#ngFor) and [NgIf](template-syntax.html#ngIf).
@@ -49,29 +49,19 @@ a#write-directive
4949
the attribute.
5050
The controller class implements the desired directive behavior.
5151

52-
This page demonstrates building a simple attribute
52+
This page demonstrates building a simple _myHighlight_ attribute
5353
directive to set an element's background color
54-
when the user hovers over that element.
55-
.l-sub-section
56-
:marked
57-
Technically, a directive isn't necessary to simply set the background color. Style binding can set styles as follows:
58-
59-
+makeExample('attribute-directives/ts/src/app/app.component.1.html','p-style-background')
60-
61-
:marked
62-
Read more about [style binding](template-syntax.html#style-binding) on the [Template Syntax](template-syntax.html) page.
63-
64-
For a simple example, though, this will demonstrate how attribute directives work.
65-
54+
when the user hovers over that element. You can apply it like this:
6655

56+
+makeExample('attribute-directives/ts/src/app/app.component.1.html','applied')
6757

6858
:marked
6959
### Write the directive code
70-
Follow the [setup](setup.html) instructions for creating a new project
60+
Follow the [setup](setup.html) instructions for creating a new local project
7161
named <span ngio-ex>attribute-directives</span>.
7262

7363
:marked
74-
Create the following source file in the indicated folder with the following code:
64+
Create the following source file in `src/app` with the following code:
7565
+makeExample('src/app/highlight.directive.1.ts')
7666

7767
block highlight-directive-1
@@ -91,14 +81,14 @@ block highlight-directive-1
9181
The [CSS selector for an attribute](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors)
9282
is the attribute name in square brackets.
9383
Here, the directive's selector is `[myHighlight]`.
94-
Angular will locate all elements in the template that have an attribute named `myHighlight`.
84+
Angular locates all elements in the template that have an attribute named `myHighlight`.
9585
.l-sub-section
9686
:marked
9787
### Why not call it "highlight"?
9888
Though *highlight* is a more concise name than *myHighlight* and would work,
9989
a best practice is to prefix selector names to ensure
10090
they don't conflict with standard HTML attributes.
101-
This also reduces the risk colliding with third-party directive names.
91+
This also reduces the risk of colliding with third-party directive names.
10292

10393
Make sure you do **not** prefix the `highlight` directive name with **`ng`** because
10494
that prefix is reserved for Angular and using it could cause bugs that are difficult to diagnose. For a simple demo, the short prefix, `my`, helps distinguish your custom directive.
@@ -120,7 +110,7 @@ a#apply-directive
120110
## Apply the attribute directive
121111
To use the new `HighlightDirective`, create a template that
122112
applies the directive as an attribute to a paragraph (`<p>`) element.
123-
In Angular terms, the `<p>` element will be the attribute **host**.
113+
In Angular terms, the `<p>` element is the attribute **host**.
124114
p
125115
| Put the template in its own
126116
code #[+adjExPath('app.component.html')]
@@ -210,7 +200,7 @@ a#bindings
210200
## Pass values into the directive with an _@Input_ data binding
211201

212202
Currently the highlight color is hard-coded _within_ the directive. That's inflexible.
213-
Let the user of the directive set the color in the template with a binding.
203+
In this section, you give the developer the power to set the highlight color while applying the directive.
214204

215205
Start by adding a `highlightColor` property to the directive class like this:
216206
+makeExample('attribute-directives/ts/src/app/highlight.directive.2.ts','color', 'src/app/highlight.directive.ts')
@@ -300,8 +290,9 @@ a#second-property
300290
## Bind to a second property
301291
This highlight directive has a single customizable property. In a real app, it may need more.
302292

303-
At the moment, the default color &mdash; the color that prevails until the user picks a highlight color &mdash;
304-
is hard-coded as "red". Let the template developer set the default color.
293+
At the moment, the default color&mdash;the color that prevails until
294+
the user picks a highlight color&mdash;is hard-coded as "red".
295+
Let the template developer set the default color.
305296

306297
Add a second **input** property to `HighlightDirective` called `defaultColor`:
307298
+makeExcerpt('attribute-directives/ts/src/app/highlight.directive.ts', 'defaultColor','src/app/highlight.directive.ts (defaultColor)')

0 commit comments

Comments
 (0)