@@ -55,22 +55,22 @@ code-example(language="sh" class="code-shell").
55
55
### Expose heroes
56
56
Create a public property in `AppComponent` that exposes the heroes for binding.
57
57
58
- + makeExample('toh-2/ts-snippets /app.component.snippets.pt2.ts ' , 'hero-array-1' , 'app.component.ts (hero array property)' )
58
+ + makeExample('toh-2/ts/app/app .component.1.html ' , 'hero-array-1' , 'app.component.ts (hero array property)' )
59
59
60
60
:marked
61
61
The `heroes` type isn't defined because TypeScript infers it from the `HEROES` array.
62
62
63
63
.l-sub-section
64
- :marked
65
- The hero data is separated from the class implementation
66
- because ultimately the hero names will come from a data service.
64
+ :marked
65
+ The hero data is separated from the class implementation
66
+ because ultimately the hero names will come from a data service.
67
67
68
68
:marked
69
69
### Display hero names in a template
70
70
The component has `heroes`. To display the hero names in an unordered list,
71
71
insert the following chunk of HTML below the title and above the hero details.
72
72
73
- + makeExample('toh-2/ts-snippets /app.component.snippets.pt2.ts ' , 'heroes-template-1' , 'app.component.ts (heroes template)' )
73
+ + makeExample('toh-2/ts/app/app .component.1.html ' , 'heroes-template-1' , 'app.component.ts (heroes template)' ) ( format = '. ')
74
74
75
75
:marked
76
76
Now you can fill the template with hero names.
@@ -82,7 +82,7 @@ code-example(language="sh" class="code-shell").
82
82
83
83
Modify the `<li>` tag by adding the built-in directive `*ngFor`.
84
84
85
- + makeExample('toh-2/ts-snippets /app.component.snippets.pt2.ts ' , 'heroes-ngfor-1' , 'app.component.ts (ngFor)' )
85
+ + makeExample('toh-2/ts/app/app .component.1.html ' , 'heroes-ngfor-1' , 'app.component.ts (ngFor)' )
86
86
87
87
.alert.is-critical
88
88
:marked
@@ -116,7 +116,7 @@ code-example(language="sh" class="code-shell").
116
116
In the `<li>` tags, add content
117
117
that uses the `hero` template variable to display the hero's properties.
118
118
119
- + makeExample('toh-2/ts-snippets /app.component.snippets.pt2.ts ' , 'ng-for' , 'app.component.ts (ngFor template)' )( format ="." )
119
+ + makeExample('toh-2/ts/app/app .component.1.html ' , 'ng-for' , 'app.component.ts (ngFor template)' )( format ="." )
120
120
121
121
:marked
122
122
When the browser refreshes, a list of heroes displays.
@@ -127,7 +127,7 @@ code-example(language="sh" class="code-shell").
127
127
To add styles to your component, set the `styles` property on the `@Component` decorator
128
128
to the following CSS classes:
129
129
130
- + makeExample('toh-2/ts/app/app.component.ts' , 'styles' , 'app.component.ts (styles)' )( format = "." )
130
+ + makeExample('toh-2/ts/app/app.component.ts' , 'styles' , 'app.component.ts (styles)' )
131
131
132
132
:marked
133
133
Notice that again you used the backtick notation for multi-line strings.
@@ -139,7 +139,7 @@ code-example(language="sh" class="code-shell").
139
139
140
140
The template for displaying heroes should look like this:
141
141
142
- + makeExample('toh-2/ts-snippets /app.component.snippets.pt2.ts ' , 'heroes-styled' , 'app.component.ts (styled heroes)' )
142
+ + makeExample('toh-2/ts/app/app .component.1.html ' , 'heroes-styled' , 'app.component.ts (styled heroes)' ) ( format = '. ')
143
143
144
144
.l-main-section
145
145
:marked
@@ -157,7 +157,7 @@ code-example(language="sh" class="code-shell").
157
157
### Add a click event
158
158
Modify the `<li>` by inserting an Angular event binding to its click event.
159
159
160
- + makeExample('toh-2/ts-snippets /app.component.snippets.pt2.ts ' , 'selectedHero-click' , 'app.component.ts (template excerpt)' )
160
+ + makeExample('toh-2/ts/app/app .component.1.html ' , 'selectedHero-click' , 'app.component.ts (template excerpt)' ) ( format = '. ')
161
161
162
162
:marked
163
163
Notice the event binding:
@@ -187,13 +187,13 @@ code-example(language="sh" class="code-shell").
187
187
you won't initialize the `selectedHero` as you did with `hero`.
188
188
189
189
Add an `onSelect` method that sets the `selectedHero` property to the `hero` that the user clicks.
190
- + makeExample('toh-2/ts/app/app.component.ts' , 'on-select' , 'app.component.ts (onSelect)' )
190
+ + makeExample('toh-2/ts/app/app.component.ts' , 'on-select' , 'app.component.ts (onSelect)' )( format = '.' )
191
191
192
192
:marked
193
193
At the moment, the template still refers to the old `hero` property.
194
194
To change the template to bind to the new `selectedHero` property, update the code as follows:
195
195
196
- + makeExample('toh-2/ts-snippets /app.component.snippets.pt2.ts ' , 'selectedHero-details' , 'app.component.ts (template excerpt)' )
196
+ + makeExample('toh-2/ts/app/app .component.1.html ' , 'selectedHero-details' , 'app.component.ts (template excerpt)' ) ( format = '. ')
197
197
:marked
198
198
### Hide the empty detail with ngIf
199
199
@@ -212,7 +212,7 @@ code-example(language="sh" class="code-shell").
212
212
Wrap the HTML hero detail content of your template with a `<div>`.
213
213
Then add the `ngIf` built-in directive and set it to the `selectedHero` property of the component.
214
214
215
- + makeExample('toh-2/ts-snippets /app.component.snippets.pt2.ts ' , 'ng-if' , 'app.component.ts (ngIf)' )
215
+ + makeExample('toh-2/ts/app/app .component.1.html ' , 'ng-if' , 'app.component.ts (ngIf)' ) ( format = '. ')
216
216
217
217
:marked
218
218
The list of names displays again in the browser.
@@ -263,15 +263,15 @@ code-example(language="sh" class="code-shell").
263
263
You can set the class to an expression that compares the current `selectedHero` to the `hero`.
264
264
265
265
The key is the name of the CSS class (`selected`). The value is `true` if the two heroes match and `false` if they don't.
266
- + makeExample('toh-2/ts-snippets /app.component.snippets.pt2.ts ' , 'class-selected-1' , 'app.component.ts (setting the CSS class)' )( format ="." )
266
+ + makeExample('toh-2/ts/app/app .component.1.html ' , 'class-selected-1' , 'app.component.ts (setting the CSS class)' )( format ="." )
267
267
:marked
268
268
Notice that `class.selected` is surrounded by square brackets (`[]`).
269
269
This is the syntax for a *property binding*, in which data flows one way
270
270
from the data source (the expression `hero === selectedHero`) to a property of `class`.
271
271
// CF: What is the preferred style for introduced terms? In this page I see two: quotes (used in
272
272
"master-detail" on line 151 and "structural directives" on line 241) and italics (used in
273
273
*property binding* on line 270).
274
- + makeExample('toh-2/ts-snippets /app.component.snippets.pt2.ts ' , 'class-selected-2' , 'app.component.ts (styling each hero)' )( format ="." )
274
+ + makeExample('toh-2/ts/app/app .component.1.html ' , 'class-selected-2' , 'app.component.ts (styling each hero)' )( format ="." )
275
275
276
276
.l-sub-section
277
277
:marked
0 commit comments