@@ -196,36 +196,23 @@ figure.image-display
196
196
197
197
### Pass values, not elements
198
198
199
- We could have passed the `newHero` into the component's `addHero` method.
200
-
201
- But that would require `addHero` to pick its way through the `<input>` DOM element,
202
- something we learned to dislike in our first try at a [keyup component](#keyup1).
203
-
204
- Instead, we grab the input box *value* and pass *that* to `addHero`.
205
- The component knows nothing about HTML or the DOM, which is the way we like it.
199
+ Instead of passing the `newHero` into the component's `addHero` method,
200
+ get the input box value and pass *that* to `addHero`.
206
201
207
202
### Keep template statements simple
208
- We bound `(blur)` to *two* JavaScript statements.
209
-
210
- We like the first one, which calls `addHero`.
211
- We do not like the second one, which assigns an empty string to the input box value.
212
-
213
- The second statement exists for a good reason. We have to clear the input box after adding the new hero to the list.
214
- The component has no way to do that itself because it has no access to the
215
- input box (our design choice).
216
-
217
- Although the example *works*, we are rightly wary of JavaScript in HTML.
218
- Template statements are powerful. We're supposed to use them responsibly.
219
- Complex JavaScript in HTML is irresponsible.
220
-
221
- Should we reconsider our reluctance to pass the input box into the component?
222
-
223
- There should be a better third way. And there is, as we'll see when we learn about `NgModel` in the [Forms](forms.html) chapter.
203
+ The `(blur)` event is bound to two JavaScript statements.
204
+ The first statement calls `addHero`. The second statement, `newHero.value=''`,
205
+ clears the input box after a new hero is added to the list.
206
+
207
+ This works well enough for a demonstration, but
208
+ it is better not to combine JavaScript and HTML.
209
+ This example can be improved by using `NgModel`, as described in
210
+ [Forms](./forms.html).
224
211
.l-main-section
225
212
:marked
226
213
## Source code
227
214
228
- Here is all the code we talked about in this chapter .
215
+ Following is all the code discussed in this page .
229
216
+ makeTabs(`
230
217
user-input/ts/app/click-me.component.ts,
231
218
user-input/ts/app/keyup.components.ts,
@@ -241,10 +228,11 @@ figure.image-display
241
228
:marked
242
229
## Summary
243
230
244
- We've mastered the basic primitives for responding to user input and gestures.
245
- As powerful as these primitives are, they are a bit clumsy for handling
246
- large amounts of user input. We're operating down at the low level of events when
247
- we should be writing two-way bindings between data entry fields and model properties.
231
+ You have mastered the basic primitives for responding to user input and gestures.
248
232
249
- Angular has a two-way binding called `NgModel`, which we'll learn about
250
- in the `Forms` chapter.
233
+ These techniques are useful for small-scale demonstrations, but they
234
+ quickly become verbose and clumsy when handling large amounts of user input.
235
+ Two-way data binding is a more elegant and compact way to move
236
+ values between data entry fields and model properties.
237
+ The next page, `Forms`, explains how to write
238
+ two-way bindings with `NgModel`.
0 commit comments