@@ -223,6 +223,12 @@ figure.image-display
223
223
224
224
*You're not using Angular yet*. There are no bindings or extra directives, just layout.
225
225
226
+ .l-sub-section
227
+ :marked
228
+ In template driven forms, if you've imported `FormsModule`, you don't have to do anything
229
+ to the `<form>` tag in order to make use of `FormsModule`. Continue on to see how this works.
230
+
231
+ :marked
226
232
The `container`, `form-group`, `form-control`, and `btn` classes
227
233
come from [Twitter Bootstrap](http://getbootstrap.com/css/). These classes are purely cosmetic.
228
234
Bootstrap gives the form a little style.
@@ -292,6 +298,31 @@ figure.image-display
292
298
:marked
293
299
Focus on the binding syntax: `[(ngModel)]="..."`.
294
300
301
+ You need one more addition to display the data. Declare
302
+ a template variable for the form. Update the `<form>` tag with
303
+ `#heroForm="ngForm"` as follows:
304
+
305
+ + makeExcerpt('src/app/hero-form.component.html (excerpt)' , 'template-variable' )
306
+
307
+ :marked
308
+ The variable `heroForm` is now a reference to the `NgForm` directive that governs the form as a whole.
309
+
310
+ .l-sub-section #ngForm
311
+ :marked
312
+ ### The _NgForm_ directive
313
+
314
+ What `NgForm` directive?
315
+ You didn't add an [NgForm](../api/forms/index/NgForm-directive.html) directive.
316
+
317
+ Angular did. Angular automatically creates and attaches an `NgForm` directive to the `<form>` tag.
318
+
319
+ The `NgForm` directive supplements the `form` element with additional features.
320
+ It holds the controls you created for the elements with an `ngModel` directive
321
+ and `name` attribute, and monitors their properties, including their validity.
322
+ It also has its own `valid` property which is true only *if every contained
323
+ control* is valid.
324
+
325
+ :marked
295
326
If you ran the app now and started typing in the *Name* input box,
296
327
adding and deleting characters, you'd see them appear and disappear
297
328
from the interpolated text.
@@ -321,7 +352,7 @@ figure.image-display
321
352
Internally, Angular creates `FormControl` instances and
322
353
registers them with an `NgForm` directive that Angular attached to the `<form>` tag.
323
354
Each `FormControl` is registered under the name you assigned to the `name` attribute.
324
- Read more in [The NgForm directive](#ngForm), later in this page .
355
+ Read more in the previous section, [The NgForm directive](#ngForm).
325
356
326
357
:marked
327
358
Add similar `[(ngModel)]` bindings and `name` attributes to *Alter Ego* and *Hero Power*.
@@ -544,25 +575,9 @@ figure.image-display
544
575
+ makeExcerpt('forms/ts/src/app/hero-form.component.html (ngSubmit)' )
545
576
546
577
:marked
547
- You added something extra at the end. You defined a
548
- template reference variable, `#heroForm`, and initialized it with the value "ngForm".
549
-
550
- The variable `heroForm` is now a reference to the `NgForm` directive that governs the form as a whole.
551
-
552
- .l-sub-section #ngForm
553
- :marked
554
- ### The _NgForm_ directive
555
-
556
- What `NgForm` directive?
557
- You didn't add an [NgForm](../api/forms/index/NgForm-directive.html) directive.
558
-
559
- Angular did. Angular automatically creates and attaches an `NgForm` directive to the `<form>` tag.
560
-
561
- The `NgForm` directive supplements the `form` element with additional features.
562
- It holds the controls you created for the elements with an `ngModel` directive
563
- and `name` attribute, and monitors their properties, including their validity.
564
- It also has its own `valid` property which is true only *if every contained
565
- control* is valid.
578
+ You'd already defined a template reference variable,
579
+ `#heroForm`, and initialized it with the value "ngForm".
580
+ Now, use that variable to access the form with the Submit button.
566
581
567
582
:marked
568
583
You'll bind the form's overall validity via
0 commit comments