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

Commit d5e213b

Browse files
committed
docs(guide): copyedit displaying-data
Also fix a few intros while I'm in _data.json. closes #659
1 parent 6dd9fd9 commit d5e213b

File tree

2 files changed

+60
-67
lines changed

2 files changed

+60
-67
lines changed

public/docs/ts/latest/guide/_data.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515

1616
"displaying-data": {
1717
"title": "Displaying Data",
18-
"intro": "In Angular, we display data by binding component properties to elements in HTML templates using interpolation and other forms of Property Binding."
18+
"intro": "Interpolation and other forms of property binding help us show app data in the UI."
1919
},
2020

2121
"user-input": {
2222
"title": "User Input",
23-
"intro": "User input triggers DOM events. We listen to those events with EventBindings that funnel updated values back into our components and models."
23+
"intro": "User input triggers DOM events. We listen to those events with event bindings that funnel updated values back into our components and models."
2424
},
2525

2626
"forms": {
@@ -35,24 +35,24 @@
3535

3636
"template-syntax": {
3737
"title": "Template Syntax",
38-
"intro": "How to write templates that display data and consume user events with the help of data binding."
38+
"intro": "Learn how to write templates that display data and consume user events with the help of data binding."
3939
},
4040

4141
"pipes": {
4242
"title": "Pipes",
43-
"intro": "Pipes transform displayed values within a template"
43+
"intro": "Pipes transform displayed values within a template."
4444
},
4545

4646
"router": {
4747
"title": "Routing & Navigation",
48-
"intro": "Discover the basics of screen navigation with the Angular 2 router"
48+
"intro": "Discover the basics of screen navigation with the Angular 2 router."
4949
},
50-
50+
5151
"lifecycle-hooks": {
5252
"title": "Lifecycle Hooks",
53-
"intro": "Angular calls lifecycle hook methods on our directives and components as it creates, changes, and destroys them."
53+
"intro": "Angular calls lifecycle hook methods on directives and components as it creates, changes, and destroys them."
5454
},
55-
55+
5656
"attribute-directives": {
5757
"title": "Attribute Directives",
5858
"intro": "Attribute directives attach behavior to elements."

public/docs/ts/latest/guide/displaying-data.jade

Lines changed: 52 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@ include ../../../../_includes/_util-fns
33
<!-- http://plnkr.co/edit/x9JYbC -->
44

55
:marked
6-
## Displaying Component Properties
7-
86
We typically display data in Angular by binding controls in an HTML template
9-
to properties of an Angular Component.
7+
to properties of an Angular component.
108

119
In this chapter, we'll create a component with a list of heroes. Each hero has a name.
1210
We'll display the list of hero names and
1311
conditionally show a selected hero in a detail area below the list.
1412

15-
[Live Example](/resources/live-examples/displaying-data/ts/plnkr.html)
16-
17-
Our final UI looks like this:
13+
The final UI looks like this:
1814

1915
figure.image-display
2016
img(src="/resources/images/devguide/displaying-data/final.png" alt="Final UI")
2117

18+
:marked
19+
[Run the live example](/resources/live-examples/displaying-data/ts/plnkr.html)
20+
2221
<a id="interpolation"></a>
2322
.l-main-section
2423
:marked
@@ -39,25 +38,25 @@ figure.image-display
3938
:marked
4039
We added two properties to the formerly empty component: `title` and `myHero`.
4140

42-
Our revised template displays the two component properties using the double curly brace
41+
Our revised template displays the two component properties using double curly brace
4342
interpolation:
4443

4544
+makeExample('displaying-data/ts/app/app.component.1.ts', 'template')(format=".")
4645
.l-sub-section
4746
:marked
48-
The template is a multi-line string within ECMAScript 2015 back-tics (\`).
49-
The back-tick (\`) is not the same character as a single quote (').
50-
It has many nice features. The feature we're exploiting is
51-
the ability to compose the string over several lines which
52-
makes for much more readable HTML.
47+
The template is a multi-line string within ECMAScript 2015 backticks (\`).
48+
The backtick (\`) &mdash; which is *not* the same character as a single
49+
quote (') &mdash; has many nice features. The feature we're exploiting here
50+
is the ability to compose the string over several lines, which makes for
51+
much more readable HTML.
5352

5453
:marked
5554
Angular automatically pulls the value of the `title` and `myHero` properties from the component and
56-
inserts those values into the browser. Angular will update the display
55+
inserts those values into the browser. Angular updates the display
5756
when these properties change.
5857
.l-sub-section
5958
:marked
60-
More precisely, the re-display occurs after some kind of asynchronous event related to
59+
More precisely, the redisplay occurs after some kind of asynchronous event related to
6160
the view such as a keystroke, a timer completion, or an async `XHR` response.
6261
We don't have those in this sample.
6362
But then the properties aren't changing on their own either. For the moment we must operate on faith.
@@ -88,12 +87,14 @@ figure.image-display
8887
## Template inline or template file?
8988

9089
We can store our component's template in one of two places.
91-
We can define it "inline" using the template property as we do here.
90+
We can define it *inline* using the `template` property, as we do here.
9291
Or we can define the template in a separate HTML file and link to it in
9392
the component metadata using the `@Component` decorator's `templateUrl` property.
9493

95-
We're using the *inline* style because the template is small and it makes for clearer demonstration.
96-
The choice between them is a matter of taste, circumstances, and organization policy.
94+
The choice between inline and separate HTML is a matter of taste,
95+
circumstances, and organization policy.
96+
Here we're using inline HTML because the template is small, and the demo
97+
is simpler without the HTML file.
9798

9899
In either style, the template data bindings have the same access to the component's properties.
99100

@@ -106,7 +107,7 @@ figure.image-display
106107
+makeExample('displaying-data/ts/app/app-ctor.component.ts', 'app-ctor')(format=".")
107108

108109
:marked
109-
That's fine too. The choice between them is a matter of taste and organization policy.
110+
That's fine too. The choice is a matter of taste and organization policy.
110111
We'll adopt the more terse "variable assignment" style in this chapter simply because
111112
there will be less code to read.
112113

@@ -116,11 +117,11 @@ figure.image-display
116117
## Showing an array property with NgFor
117118

118119
We want to display a list of heroes. We begin by adding a mock heroes name array to the component,
119-
just above `myHero` and redefine `myHero` to be the first name in the array.
120+
just above `myHero`, and redefine `myHero` to be the first name in the array.
120121
+makeExample('displaying-data/ts/app/app.component.2.ts', 'mock-heroes', 'app/app.component.ts (class)')(format=".")
121122

122123
:marked
123-
Now we use the Angular `NgFor` "repeater" Directive in the template to display
124+
Now we use the Angular `NgFor` "repeater" directive in the template to display
124125
each item in the `heroes` list.
125126

126127
+makeExample('displaying-data/ts/app/app.component.2.ts', 'template','app/app.component.ts (template)')(format=".")
@@ -132,19 +133,19 @@ figure.image-display
132133
:marked
133134
We added a somewhat mysterious `*ngFor` to the `<li>` element.
134135
That's the Angular "repeater" directive.
135-
It's presence on the `<li>` tag marks that `<li>` element (and its children) as the "repeater template".
136+
Its presence on the `<li>` tag marks that `<li>` element (and its children) as the "repeater template".
136137

137138
.alert.is-important
138139
:marked
139-
Don't forget the leading asterisk (\*) in front of `*ngFor`. It is an essential part of the syntax.
140+
Don't forget the leading asterisk (\*) in `*ngFor`. It is an essential part of the syntax.
140141
Learn more about this and `NgFor` in the [Template Syntax](./template-syntax.html#ngFor) chapter.
141142

142143
:marked
143144
Notice the `#hero` in the `NgFor` double-quoted instruction.
144-
The `#hero` is a "[template local variable](./template-syntax.html#local-vars")" *declaration*.
145-
The (#) prefix declares a local variable name named `hero`.
145+
The `#hero` is a [local template variable](./template-syntax.html#local-vars) declaration.
146+
The `#` prefix declares a local variable name named `hero`.
146147

147-
Angular will duplicate the `<li>` for each item in the list, setting the `hero` variable
148+
Angular duplicates the `<li>` for each item in the list, setting the `hero` variable
148149
to the item (the hero) in the current iteration. Angular uses that variable as the
149150
context for the interpolation in the double curly braces.
150151

@@ -168,67 +169,67 @@ figure.image-display
168169
That's fine for a demo but certainly isn't a best practice. It's not even a good practice.
169170
Although we won't do anything about that in this chapter, we'll make a mental note to fix this down the road.
170171

171-
At the moment, we're binding to an array of strings. We do that occasionally in real applications but
172-
most of the time we're displaying objects, potentially instances of classes.
172+
At the moment, we're binding to an array of strings. We do that occasionally in real applications, but
173+
most of the time we're displaying objects &mdash; potentially instances of classes.
173174

174-
Let's turn our array of hero names into an array of `Hero` objects. For that we'll need a `Hero' class.
175+
Let's turn our array of hero names into an array of `Hero` objects. For that we'll need a `Hero` class.
175176

176177
Create a new file in the `app/` folder called `hero.ts` with the following short bit of code.
177178
+makeExample('displaying-data/ts/app/hero.ts', null, 'app/hero.ts')(format = ".")
178179

179180
:marked
180181
We've defined a class with a constructor and two properties: `id` and `name`.
181182

182-
If we are new to TypeScript, it may not look like we have properties. But we do. We're taking
183-
advantage of a TypeScript short-cut in our declaration of the constructor parameters.
183+
It might not look like we have properties, but we do. We're taking
184+
advantage of a TypeScript shortcut in our declaration of the constructor parameters.
184185

185186
Consider the first parameter:
186187
+makeExample('displaying-data/ts/app/hero.ts', 'id-parameter')
187188

188189
:marked
189-
That brief syntax simultaneously
190+
That brief syntax does a lot:
190191
* declares a constructor parameter and its type
191-
* declare a public property of the same name
192-
* initializes that property with the corresponding argument when we "new" an instance of the class.
192+
* declares a public property of the same name
193+
* initializes that property with the corresponding argument when we "new" an instance of the class
193194

194195
.l-main-section
195196
:marked
196-
## Use the Hero class
197-
Let's redefine the heroes property in our component to return an array of these Heroes
197+
## Using the Hero class
198+
Let's redefine the `heroes` property in our component to return an array of these Hero objects
198199
and also set the `myHero` property with the first of these mock heroes.
199200
+makeExample('displaying-data/ts/app/app.component.3.ts', 'heroes', 'app.component.ts (excerpt)')(format=".")
200201

201202
:marked
202203
We'll have to update the template.
203-
At the moment it displays the entire hero object which used to be a string value.
204-
Let's fix that so we interpolate the `hero.name` property
204+
At the moment it displays the entire `hero` object, which used to be a string value.
205+
Let's fix that so we interpolate the `hero.name` property.
205206
+makeExample('displaying-data/ts/app/app.component.3.ts', 'template','app.component.ts (template)')(format=".")
206207

207208
:marked
208-
Our display looks the same but we know how much better it is under the hood.
209+
Our display looks the same, but now we know much better what a hero really is.
209210

210211
<a id="ngIf"></a>
211212
.l-main-section
212213
:marked
213214
## Conditional display with NgIf
214215

215-
Sometimes the app should display a view or a portion of a view only under prescribed circumstances.
216+
Sometimes the app should display a view or a portion of a view only under specific circumstances.
216217

217-
In our example, we'd like to display a message if we have a large number of heroes ... say more than 3.
218+
In our example, we'd like to display a message if we have a large number of heroes &mdash; say, more than 3.
218219

219-
The Angular `NgIf` directive will insert or remove an element based on a truthy/falsey condition.
220+
The Angular `NgIf` directive inserts or removes an element based on a truthy/falsey condition.
220221
We can see it in action by adding the following paragraph at the bottom of the template:
221222
+makeExample('displaying-data/ts/app/app.component.ts', 'message')
222223
.alert.is-important
223224
:marked
224-
Don't forget the leading asterisk (\*) in front of `*ngIf`. It is an essential part of the syntax.
225+
Don't forget the leading asterisk (\*) in `*ngIf`. It is an essential part of the syntax.
225226
Learn more about this and `NgIf` in the [Template Syntax](./template-syntax.html#ngIf) chapter.
226227

227228
:marked
228229
The [template expression](./template-syntax.html#template-expressions) inside the double quotes
229-
looks much like JavaScript and it is much like JavaScript.
230+
looks much like JavaScript and it _is_ much like JavaScript.
230231
When the component's list of heroes has more than 3 items, Angular adds the paragraph to the DOM and the message appears.
231-
If there were 3 or fewer items, Angular omits the paragraph and there is no message.
232+
If there are 3 or fewer items, Angular omits the paragraph, so no message appears.
232233

233234
.alert.is-helpful
234235
:marked
@@ -237,31 +238,23 @@ figure.image-display
237238
we were conditionally including or excluding a big chunk of HTML with many data bindings.
238239

239240
:marked
240-
Try it out. We have four items in the array so the message should appear.
241+
Try it out. Because the array has four items, the message should appear.
241242
Go back into `app.component.ts` and delete or comment out one of the elements from the hero array.
242243
The browser should refresh automatically and the message should disappear.
243244

244-
Play with it.
245-
246245
.l-main-section
247246
:marked
248247
## Summary
249-
Now we know how to
250-
- use **interpolation** with the double curly braces to display a component property,
251-
- use **`NgFor`** to display a list of items,
252-
- use a TypeScript class to shape the model data for our component and display properties of that model,
253-
- use **`NgIf`** to conditionally display a chunk of HTML based on a boolean expression.
248+
Now we know how to use:
249+
- **interpolation** with double curly braces to display a component property
250+
- **`NgFor`** to display a list of items
251+
- a TypeScript class to shape the **model data** for our component and display properties of that model
252+
- **`NgIf`** to conditionally display a chunk of HTML based on a boolean expression
254253

255-
Our final code:
254+
Here's our final code:
256255

257256
+makeTabs(`displaying-data/ts/app/app.component.ts,
258257
displaying-data/ts/app/hero.ts,
259258
displaying-data/ts/app/boot.ts`,
260259
'final,,',
261260
'app/app.component.ts, app/hero.ts, boot.ts')
262-
263-
.l-main-section
264-
:marked
265-
## Next Steps
266-
In addition to displaying data, most applications need to respond to user input.
267-
Learn about that in the [User Input](./user-input.html) chapter.

0 commit comments

Comments
 (0)