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

Commit 6c7f330

Browse files
kapunahelewongkwalrath
authored andcommitted
docs(Displaying Data): copy edits (#2435)
1 parent 4bb7995 commit 6c7f330

File tree

2 files changed

+85
-90
lines changed

2 files changed

+85
-90
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
"displaying-data": {
1919
"title": "Displaying Data",
20-
"intro": "Interpolation and other forms of property binding help us show app data in the UI.",
20+
"intro": "Property binding helps show app data in the UI.",
2121
"nextable": true,
2222
"basics": true
2323
},

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

Lines changed: 84 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ block includes
22
include ../_util-fns
33
- var _iterableUrl = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols';
44
- var _boolean = 'truthy/falsey';
5-
5+
66
:marked
7-
We typically display data in Angular by binding controls in an HTML template
8-
to properties of an Angular component.
7+
You can display data by binding controls in an HTML template to properties of an Angular component.
98

10-
In this chapter, we'll create a component with a list of heroes. Each hero has a name.
11-
We'll display the list of hero names and
9+
In this page, you'll create a component with a list of heroes.
10+
You'll display the list of hero names and
1211
conditionally show a message below the list.
1312

1413
The final UI looks like this:
@@ -17,42 +16,42 @@ figure.image-display
1716
img(src="/resources/images/devguide/displaying-data/final.png" alt="Final UI")
1817

1918
:marked
20-
# Table Of Contents
19+
# Contents
2120

22-
* [Showing component properties with interpolation](#interpolation)
23-
* [Showing !{_an} !{_array} property with NgFor](#ngFor)
24-
* [Conditional display with NgIf](#ngIf)
21+
* [Showing component properties with interpolation](#interpolation).
22+
* [Showing !{_an} !{_array} property with NgFor](#ngFor).
23+
* [Conditional display with NgIf](#ngIf).
2524

2625
.l-sub-section
2726
:marked
2827
The <live-example></live-example> demonstrates all of the syntax and code
29-
snippets described in this chapter.
28+
snippets described in this page.
3029

3130
.l-main-section#interpolation
3231
:marked
3332
## Showing component properties with interpolation
3433
The easiest way to display a component property
3534
is to bind the property name through interpolation.
36-
With interpolation, we put the property name in the view template, enclosed in double curly braces: `{{myHero}}`.
37-
38-
Let's build a small illustrative example together.
35+
With interpolation, you put the property name in the view template, enclosed in double curly braces: `{{myHero}}`.
3936

40-
Create a new project folder (<ngio-ex path="displaying-data"></ngio-ex>) and follow the steps in the [QuickStart](../quickstart.html).
37+
To build an illustrative example, start by creating a new project folder called <ngio-ex path="displaying-data"></ngio-ex>
38+
and following the steps in [QuickStart](../quickstart.html).
4139

4240
block quickstart-repo
4341
include ../_quickstart_repo
4442

4543
:marked
46-
Then modify the <ngio-ex path="app.component.ts"></ngio-ex> file by
44+
Then modify the <ngio-ex path="app.component.ts"></ngio-ex> file by
4745
changing the template and the body of the component.
48-
When we're done, it should look like this:
46+
47+
When you're done, it should look like this:
4948

5049
+makeExample('app/app.component.1.ts')
5150

5251
:marked
53-
We added two properties to the formerly empty component: `title` and `myHero`.
52+
You added two properties to the formerly empty component: `title` and `myHero`.
5453

55-
Our revised template displays the two component properties using double curly brace
54+
The revised template displays the two component properties using double curly brace
5655
interpolation:
5756

5857
+makeExcerpt('app/app.component.1.ts', 'template', '')
@@ -61,10 +60,9 @@ block quickstart-repo
6160
.l-sub-section
6261
:marked
6362
The template is a multi-line string within ECMAScript 2015 backticks (<code>\`</code>).
64-
The backtick (<code>\`</code>) &mdash; which is *not* the same character as a single
65-
quote (`'`) &mdash; has many nice features. The feature we're exploiting here
66-
is the ability to compose the string over several lines, which makes for
67-
much more readable HTML.
63+
The backtick (<code>\`</code>)&mdash;which is *not* the same character as a single
64+
quote (`'`)&mdash;allows you to compose a string over several lines, which makes the
65+
HTML more readable.
6866

6967
:marked
7068
Angular automatically pulls the value of the `title` and `myHero` properties from the component and
@@ -74,43 +72,42 @@ block quickstart-repo
7472
.l-sub-section
7573
:marked
7674
More precisely, the redisplay occurs after some kind of asynchronous event related to
77-
the view such as a keystroke, a timer completion, or an async `XHR` response.
78-
We don't have those in this sample.
79-
But then the properties aren't changing on their own either. For the moment we must operate on faith.
75+
the view, such as a keystroke, a timer completion, or a response to an HTTP request.
8076

8177
:marked
82-
Notice that we haven't called **new** to create an instance of the `AppComponent` class.
83-
Angular is creating an instance for us. How?
78+
Notice that you don't call **new** to create an instance of the `AppComponent` class.
79+
Angular is creating an instance for you. How?
8480

85-
Notice the CSS `selector` in the `@Component` !{_decorator} that specifies an element named `my-app`.
86-
Remember back in [QuickStart](../quickstart.html) that we added the `<my-app>` element to the body of our `index.html` file:
81+
The CSS `selector` in the `@Component` !{_decorator} specifies an element named `my-app`.
82+
Remember back in [QuickStart](../quickstart.html) that you added the `<my-app>`
83+
element to the body of your `index.html` file:
8784

8885
+makeExcerpt('index.html', 'body')
8986

9087
:marked
91-
When we bootstrap with the `AppComponent` class (in <ngio-ex path="main.ts"></ngio-ex>), Angular looks for a `<my-app>`
88+
When you bootstrap with the `AppComponent` class (in <ngio-ex path="main.ts"></ngio-ex>), Angular looks for a `<my-app>`
9289
in the `index.html`, finds it, instantiates an instance of `AppComponent`, and renders it
9390
inside the `<my-app>` tag.
9491

95-
Try running the app. It should display the title and hero name:
92+
Now run the app. It should display the title and hero name:
9693
figure.image-display
9794
img(src="/resources/images/devguide/displaying-data/title-and-hero.png" alt="Title and Hero")
9895

9996
+ifDocsFor('ts')
10097
:marked
101-
Let's review some of the choices we made and consider alternatives.
98+
The next few sections review some of the coding choices in the app.
10299

103100
:marked
104101
## Template inline or template file?
105102

106-
We can store our component's template in one of two places.
107-
We can define it *inline* using the `template` property, as we do here.
108-
Or we can define the template in a separate HTML file and link to it in
103+
You can store your component's template in one of two places.
104+
You can define it *inline* using the `template` property, or you can define
105+
the template in a separate HTML file and link to it in
109106
the component metadata using the `@Component` !{_decorator}'s `templateUrl` property.
110107

111108
The choice between inline and separate HTML is a matter of taste,
112109
circumstances, and organization policy.
113-
Here we're using inline HTML because the template is small, and the demo
110+
Here the app uses inline HTML because the template is small and the demo
114111
is simpler without the additional HTML file.
115112

116113
In either style, the template data bindings have the same access to the component's properties.
@@ -119,59 +116,53 @@ figure.image-display
119116
:marked
120117
## Constructor or variable initialization?
121118

122-
We initialized our component properties using variable assignment.
123-
This is a wonderfully concise and compact technique.
119+
Although this example uses variable assignment to initialize the components, you can instead declare and initialize the properties using a constructor:
124120

125-
Some folks prefer to declare the properties and initialize them within a constructor like this:
126121
+makeExcerpt('app/app-ctor.component.ts', 'class')
127122

128123
:marked
129-
That's fine too. The choice is a matter of taste and organization policy.
130-
We'll adopt the more terse "variable assignment" style in this chapter simply because
131-
there will be less code to read.
124+
This app uses more terse "variable assignment" style simply for brevity.
132125

133126
.l-main-section#ngFor
134127
:marked
135128
## Showing !{_an} !{_array} property with ***ngFor**
136129

137-
We want to display a list of heroes. We begin by adding !{_an} !{_array} of hero names to the component and redefine `myHero` to be the first name in the !{_array}.
130+
To display a list of heroes, begin by adding !{_an} !{_array} of hero names to the component and redefine `myHero` to be the first name in the !{_array}.
138131

139132
+makeExcerpt('app/app.component.2.ts', 'class')
140133

141134
:marked
142-
Now we use the Angular `ngFor` directive in the template to display
135+
Now use the Angular `ngFor` directive in the template to display
143136
each item in the `heroes` list.
144137

145138
+makeExcerpt('app/app.component.2.ts', 'template')
146139

147140
:marked
148-
Our presentation is the familiar HTML unordered list with `<ul>` and `<li>` tags. Let's focus on the `<li>` tag.
141+
This UI uses the HTML unordered list with `<ul>` and `<li>` tags. The `*ngFor`
142+
in the `<li>` element is the Angular "repeater" directive.
143+
It marks that `<li>` element (and its children) as the "repeater template":
149144

150145
+makeExcerpt('app/app.component.2.ts ()', 'li', '')
151146

152-
:marked
153-
We added a somewhat mysterious `*ngFor` to the `<li>` element.
154-
That's the Angular "repeater" directive.
155-
Its presence on the `<li>` tag marks that `<li>` element (and its children) as the "repeater template".
156-
157147
.alert.is-important
158148
:marked
159149
Don't forget the leading asterisk (\*) in `*ngFor`. It is an essential part of the syntax.
160-
Learn more about this and `ngFor` in the [Template Syntax](./template-syntax.html#ngFor) chapter.
150+
For more information, see the [Template Syntax](./template-syntax.html#ngFor) page.
161151

162152
:marked
163153
Notice the `hero` in the `ngFor` double-quoted instruction;
164-
it is an example of a [template input variable](./template-syntax.html#ngForMicrosyntax).
154+
it is an example of a template input variable. Read
155+
more about template input variables in the [microsyntax](./template-syntax.html#ngForMicrosyntax) section of
156+
the [Template Syntax](./template-syntax.html) page.
165157

166158
Angular duplicates the `<li>` for each item in the list, setting the `hero` variable
167159
to the item (the hero) in the current iteration. Angular uses that variable as the
168160
context for the interpolation in the double curly braces.
169161

170162
.l-sub-section
171163
:marked
172-
We happened to give `ngFor` !{_an} !{_array} to display.
173-
In fact, `ngFor` can repeat items for any [iterable](!{_iterableUrl})
174-
object.
164+
In this case, `ngFor` is displaying !{_an} !{_array}, but `ngFor` can
165+
repeat items for any [iterable](!{_iterableUrl}) object.
175166
:marked
176167
Now the heroes appear in an unordered list.
177168

@@ -182,82 +173,86 @@ figure.image-display
182173
:marked
183174
## Creating a class for the data
184175

185-
We are defining our data directly inside our component.
186-
That's fine for a demo but certainly isn't a best practice. It's not even a good practice.
187-
Although we won't do anything about that in this chapter, we'll make a mental note to fix this down the road.
176+
The app's code defines the data directly inside the component, which isn't best practice.
177+
In a simple demo, however, it's fine.
188178

189-
At the moment, we're binding to !{_an} !{_array} of strings. We do that occasionally in real applications, but
190-
most of the time we're binding to more specialized objects.
179+
At the moment, the binding is to !{_an} !{_array} of strings.
180+
In real applications, most bindings are to more specialized objects.
191181

192-
Let's turn our !{_array} of hero names into !{_an} !{_array} of `Hero` objects. For that we'll need a `Hero` class.
182+
To convert this binding to use specialized objects, turn the !{_array}
183+
of hero names into !{_an} !{_array} of `Hero` objects. For that you'll need a `Hero` class.
193184

194185
Create a new file in the `!{_appDir}` folder called <ngio-ex path="hero.ts"></ngio-ex> with the following code:
195-
186+
196187
+makeExcerpt('app/hero.ts')
197188

198189
block hero-class
199190
:marked
200-
We've defined a class with a constructor and two properties: `id` and `name`.
191+
You've defined a class with a constructor and two properties: `id` and `name`.
201192

202-
It might not look like we have properties, but we do. We're taking
203-
advantage of a TypeScript shortcut in our declaration of the constructor parameters.
193+
It might not look like the class has properties, but it does.
194+
The declaration of the constructor parameters takes advantage of a TypeScript shortcut.
204195

205196
Consider the first parameter:
206197

207198
+makeExcerpt('app/hero.ts ()', 'id')
208199

209200
:marked
210201
That brief syntax does a lot:
211-
* Declares a constructor parameter and its type
212-
* Declares a public property of the same name
213-
* Initializes that property with the corresponding argument when we "new" an instance of the class
202+
* Declares a constructor parameter and its type.
203+
* Declares a public property of the same name.
204+
* Initializes that property with the corresponding argument when creating an instance of the class.
214205

215206
.l-main-section
216207
:marked
217208
## Using the Hero class
218-
Let's make the `heroes` property in our component return !{_an} !{_array} of these `Hero` objects.
209+
210+
The `heroes` property in the component can now use the `Hero` class to return !{_an} !{_array}
211+
of `Hero` objects:
219212

220213
+makeExcerpt('app/app.component.3.ts', 'heroes')
221214

222215
:marked
223-
We'll have to update the template.
216+
Next, update the template.
224217
At the moment it displays the hero's `id` and `name`.
225-
Let's fix that so we display only the hero's `name` property.
218+
Fix that to display only the hero's `name` property.
226219

227220
+makeExcerpt('app/app.component.3.ts', 'template')
228221

229222
:marked
230-
Our display looks the same, but now we know much better what a hero really is.
223+
The display looks the same, but the code is clearer.
231224

232225
.l-main-section#ngIf
233226
:marked
234227
## Conditional display with NgIf
235228

236229
Sometimes an app needs to display a view or a portion of a view only under specific circumstances.
237230

238-
In our example, we'd like to display a message if we have a large number of heroes, say, more than 3.
231+
Let's change the example to display a message if there are more than three heroes.
239232

240233
The Angular `ngIf` directive inserts or removes an element based on a !{_boolean} condition.
241-
We can see it in action by adding the following paragraph at the bottom of the template:
234+
To see it in action, add the following paragraph at the bottom of the template:
242235

243236
+makeExcerpt('app/app.component.ts', 'message')
244237

245238
.alert.is-important
246239
:marked
247240
Don't forget the leading asterisk (\*) in `*ngIf`. It is an essential part of the syntax.
248-
Learn more about this and `ngIf` in the [Template Syntax](./template-syntax.html#ngIf) chapter.
241+
Read more about `ngIf` and `*` in the [ngIf section](./template-syntax.html#ngIf) of the [Template Syntax](./template-syntax.html) page.
249242

250243
:marked
251-
The [template expression](./template-syntax.html#template-expressions) inside the double quotes
252-
looks much like !{_Lang}, and it _is_ much like !{_Lang}.
253-
When the component's list of heroes has more than 3 items, Angular adds the paragraph to the DOM and the message appears.
254-
If there are 3 or fewer items, Angular omits the paragraph, so no message appears.
244+
The template expression inside the double quotes,
245+
`*ngIf="heros.length > 3"`, looks and behaves much like !{_Lang}.
246+
When the component's list of heroes has more than three items, Angular adds the paragraph
247+
to the DOM and the message appears. If there are three or fewer items, Angular omits the
248+
paragraph, so no message appears. For more information,
249+
see the [template expressions](./template-syntax.html#template-expressions) section of the
250+
[Template Syntax](./template-syntax.html) page.
255251

256252
.alert.is-helpful
257253
:marked
258-
Angular isn't showing and hiding the message. It is adding and removing the paragraph element from the DOM.
259-
That hardly matters here. But it would matter a great deal, from a performance perspective, if
260-
we were conditionally including or excluding a big chunk of HTML with many data bindings.
254+
Angular isn't showing and hiding the message. It is adding and removing the paragraph element from the DOM. That improves performance, especially in larger projects when conditionally including or excluding
255+
big chunks of HTML with many data bindings.
261256

262257
:marked
263258
Try it out. Because the !{_array} has four items, the message should appear.
@@ -267,18 +262,18 @@ block hero-class
267262
.l-main-section
268263
:marked
269264
## Summary
270-
Now we know how to use:
271-
- **Interpolation** with double curly braces to display a component property
272-
- **ngFor** to display !{_an} !{_array} of items
273-
- A !{_Lang} class to shape the **model data** for our component and display properties of that model
274-
- **ngIf** to conditionally display a chunk of HTML based on a boolean expression
265+
Now you know how to use:
266+
- **Interpolation** with double curly braces to display a component property.
267+
- **ngFor** to display !{_an} !{_array} of items.
268+
- A !{_Lang} class to shape the **model data** for your component and display properties of that model.
269+
- **ngIf** to conditionally display a chunk of HTML based on a boolean expression.
275270

276-
Here's our final code:
271+
Here's the final code:
277272

278273
block final-code
279274
+makeTabs(`displaying-data/ts/app/app.component.ts,
280275
displaying-data/ts/app/hero.ts,
281276
displaying-data/ts/app/app.module.ts,
282277
displaying-data/ts/app/main.ts`,
283278
'final,,,',
284-
'app/app.component.ts, app/hero.ts, app.module.ts, main.ts')
279+
'app/app.component.ts, app/hero.ts, app.module.ts, main.ts')

0 commit comments

Comments
 (0)