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

Commit 01f0f6d

Browse files
kapunahelewongwardbell
authored andcommitted
docs(forms): move template reference var higher in doc (#3521)
1 parent 10dd5b8 commit 01f0f6d

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

public/docs/_examples/forms/ts/src/app/hero-form.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ <h1>Hero Form</h1>
150150
<!-- #docregion phase2-->
151151
<div class="container">
152152
<h1>Hero Form</h1>
153-
<form>
153+
<!-- #docregion template-variable-->
154+
<form #heroForm="ngForm">
155+
<!-- #enddocregion template-variable-->
154156
<!-- #docregion ngModel-2-->
155157
{{diagnostic}}
156158
<div class="form-group">

public/docs/ts/latest/guide/forms.jade

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ figure.image-display
223223

224224
*You're not using Angular yet*. There are no bindings or extra directives, just layout.
225225

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
226232
The `container`, `form-group`, `form-control`, and `btn` classes
227233
come from [Twitter Bootstrap](http://getbootstrap.com/css/). These classes are purely cosmetic.
228234
Bootstrap gives the form a little style.
@@ -292,6 +298,31 @@ figure.image-display
292298
:marked
293299
Focus on the binding syntax: `[(ngModel)]="..."`.
294300

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
295326
If you ran the app now and started typing in the *Name* input box,
296327
adding and deleting characters, you'd see them appear and disappear
297328
from the interpolated text.
@@ -321,7 +352,7 @@ figure.image-display
321352
Internally, Angular creates `FormControl` instances and
322353
registers them with an `NgForm` directive that Angular attached to the `<form>` tag.
323354
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).
325356

326357
:marked
327358
Add similar `[(ngModel)]` bindings and `name` attributes to *Alter Ego* and *Hero Power*.
@@ -544,25 +575,9 @@ figure.image-display
544575
+makeExcerpt('forms/ts/src/app/hero-form.component.html (ngSubmit)')
545576

546577
: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.
566581

567582
:marked
568583
You'll bind the form's overall validity via

0 commit comments

Comments
 (0)