Skip to content

Commit 6bccdd0

Browse files
committed
docs(forms): add link to Dart sample
Contributes to angular#1598. Also: - Trimmed trailing whitespace. - Fixing user-input (since we don’t need the “Run the” in the link).
1 parent 9b3614d commit 6bccdd0

File tree

4 files changed

+52
-51
lines changed

4 files changed

+52
-51
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
include ../_util-fns
22

3-
<!-- http://plnkr.co/edit/wg154K -->
43
:marked
54
We’ve all used a form to log in, submit a help request, place an order, book a flight,
65
schedule a meeting, and perform countless other data entry tasks.
@@ -30,6 +29,8 @@ include ../_util-fns
3029

3130
- How to share information across controls with template reference variables
3231

32+
Run the <live-example></live-example>.
33+
3334
.l-main-section
3435
:marked
3536
## Template-driven forms

public/docs/dart/latest/guide/user-input.jade

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ include ../_util-fns
66
In this chapter we learn to bind to those events using the Angular
77
event binding syntax.
88

9-
<live-example>Run the live example</live-example>.
9+
Run the <live-example></live-example>.
1010

1111
:marked
1212
## Binding to user input events

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

+48-48
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ include ../_util-fns
2121

2222
- two-way data bind with `[(ngModel)]` syntax for reading and writing values to input controls
2323

24-
- track the change state and validity of form controls using `ngModel` in combination with a form
24+
- track the change state and validity of form controls using `ngModel` in combination with a form
2525

2626
- provide strong visual feedback using special CSS classes that track the state of the controls
2727

2828
- display validation errors to users and enable/disable form controls
2929

3030
- use [template reference variables](./template-syntax.html#ref-vars) for sharing information among HTML elements
31-
32-
<live-example>Live Example</live-example>
31+
32+
Run the <live-example></live-example>.
3333

3434
.l-main-section
3535
:marked
@@ -107,13 +107,13 @@ include ../_quickstart_repo
107107

108108
The TypeScript compiler generates a public field for each `public` constructor parameter and
109109
assigns the parameter’s value to that field automatically when we create new heroes.
110-
110+
111111
The `alterEgo` is optional and the constructor lets us omit it; note the (?) in `alterEgo?`.
112112

113113
We can create a new hero like this:
114114
code-example(format="").
115-
let myHero = new Hero(42, 'SkyDog',
116-
'Fetch any object at any distance',
115+
let myHero = new Hero(42, 'SkyDog',
116+
'Fetch any object at any distance',
117117
'Leslie Rollover');
118118
console.log('My hero is called ' + myHero.name); // "My hero is called SkyDog"
119119
:marked
@@ -159,7 +159,7 @@ code-example(format="").
159159
write (or read) large stretches of HTML and few editors are much help with files that have a mix of HTML and code.
160160
We also like short files with a clear and obvious purpose like this one.
161161

162-
We made a good choice to put the HTML template elsewhere.
162+
We made a good choice to put the HTML template elsewhere.
163163
We'll write that template in a moment. Before we do, we'll take a step back
164164
and revise the `app.module.ts` and `app.component.ts` to make use of our new `HeroFormComponent`.
165165

@@ -191,7 +191,7 @@ code-example(format="").
191191

192192
.alert.is-important
193193
:marked
194-
If a component, directive, or pipe belongs to a module in the `imports` array, ​_DON'T_​ declare it in the `declarations` array.
194+
If a component, directive, or pipe belongs to a module in the `imports` array, ​_DON'T_​ declare it in the `declarations` array.
195195
If you wrote it and it should belong to this module, ​_DO_​ declare it in the `declarations` array.
196196

197197
.l-main-section
@@ -230,7 +230,7 @@ code-example(format="").
230230

231231
**We are not using Angular yet**. There are no bindings. No extra directives. Just layout.
232232

233-
The `container`, `form-group`, `form-control`, and `btn` classes
233+
The `container`, `form-group`, `form-control`, and `btn` classes
234234
come from [Twitter Bootstrap](http://getbootstrap.com/css/). Purely cosmetic.
235235
We're using Bootstrap to gussy up our form.
236236
Hey, what's a form without a little style!
@@ -300,7 +300,7 @@ figure.image-display
300300
We appended a diagnostic interpolation after the input tag
301301
so we can see what we're doing.
302302
We left ourselves a note to throw it away when we're done.
303-
303+
304304
:marked
305305
Focus on the binding syntax: `[(ngModel)]="..."`.
306306

@@ -314,13 +314,13 @@ figure.image-display
314314
The diagnostic is evidence that we really are flowing values from the input box to the model and
315315
back again. **That's two-way data binding!**
316316

317-
Notice that we also added a `name` attribute to our `<input>` tag and set it to "name"
317+
Notice that we also added a `name` attribute to our `<input>` tag and set it to "name"
318318
which makes sense for the hero's name. Any unique value will do, but using a descriptive name is helpful.
319319
Defining a `name` attribute is a requirement when using `[(ngModel)]` in combination with a form.
320320

321321
.l-sub-section
322322
:marked
323-
Internally Angular creates `FormControls` and registers them with an `NgForm` directive that Angular
323+
Internally Angular creates `FormControls` and registers them with an `NgForm` directive that Angular
324324
attached to the `<form>` tag. Each `FormControl` is registered under the name we assigned to the `name` attribute.
325325
We'll talk about `NgForm` [later in this chapter](#ngForm).
326326

@@ -340,7 +340,7 @@ figure.image-display
340340
- Each input element has an `id` property that is used by the `label` element's `for` attribute
341341
to match the label to it's input control.
342342
- Each input element has a `name` property that is required by Angular Forms to register the control with the form.
343-
343+
344344
:marked
345345
If we ran the app right now and changed every Hero model property, the form might display like this:
346346
figure.image-display
@@ -355,7 +355,7 @@ figure.image-display
355355
:marked
356356
### Inside [(ngModel)]
357357
*This section is an optional deep dive into [(ngModel)]. Not interested? Skip ahead!*
358-
358+
359359
The punctuation in the binding syntax, <span style="font-family:courier"><b>[()]</b></span>, is a good clue to what's going on.
360360

361361
In a Property Binding, a value flows from the model to a target property on screen.
@@ -405,7 +405,7 @@ figure.image-display
405405
The *NgModel* directive doesn't just track state; it updates the control with special Angular CSS classes that reflect the state.
406406
We can leverage those class names to change the appearance of the
407407
control and make messages appear or disappear.
408-
408+
409409
table
410410
tr
411411
th State
@@ -491,32 +491,32 @@ figure.image-display
491491
1. the "*is required*" message in a nearby `<div>` which we'll display only if the control is invalid.
492492

493493
Here's how we do it for the *name* input box:
494-
+makeExample('forms/ts/app/hero-form.component.html',
495-
'name-with-error-msg',
494+
+makeExample('forms/ts/app/hero-form.component.html',
495+
'name-with-error-msg',
496496
'app/hero-form.component.html (excerpt)')(format=".")
497497
:marked
498498
We need a template reference variable to access the input box's Angular control from within the template.
499499
Here we created a variable called `name` and gave it the value "ngModel".
500500
.l-sub-section
501501
:marked
502-
Why "ngModel"?
502+
Why "ngModel"?
503503
A directive's [exportAs](../api/core/index/DirectiveMetadata-class.html#!#exportAs-anchor) property
504504
tells Angular how to link the reference variable to the directive.
505505
We set `name` to `ngModel` because the `ngModel` directive's `exportAs` property happens to be "ngModel".
506506

507507
Now we can control visibility of the "name" error message by binding properties of the `name` control to the message `<div>` element's `hidden` property.
508-
+makeExample('forms/ts/app/hero-form.component.html',
509-
'hidden-error-msg',
508+
+makeExample('forms/ts/app/hero-form.component.html',
509+
'hidden-error-msg',
510510
'app/hero-form.component.html (excerpt)')
511511
:marked
512-
In this example, we hide the message when the control is valid or pristine;
513-
pristine means the user hasn't changed the value since it was displayed in this form.
514-
512+
In this example, we hide the message when the control is valid or pristine;
513+
pristine means the user hasn't changed the value since it was displayed in this form.
514+
515515
This user experience is the developer's choice. Some folks want to see the message at all times.
516516
If we ignore the `pristine` state, we would hide the message only when the value is valid.
517-
If we arrive in this component with a new (blank) hero or an invalid hero,
517+
If we arrive in this component with a new (blank) hero or an invalid hero,
518518
we'll see the error message immediately, before we've done anything.
519-
519+
520520
Some folks find that behavior disconcerting. They only want to see the message when the user makes an invalid change.
521521
Hiding the message while the control is "pristine" achieves that goal.
522522
We'll see the significance of this choice when we [add a new hero](#new-hero) to the form.
@@ -527,30 +527,30 @@ figure.image-display
527527
We can add the same kind of error handling to the `<select>` if we want
528528
but it's not imperative because the selection box already constrains the
529529
power to valid value.
530-
530+
531531
<a id="new-hero"></a>
532-
<a id="reset"></a>
532+
<a id="reset"></a>
533533
.l-main-section
534534
:marked
535535
## Add a hero and reset the form
536-
We'd like to add a new hero in this form.
536+
We'd like to add a new hero in this form.
537537
We place a "New Hero" button at the bottom of the form and bind its click event to a component method.
538-
+makeExample('forms/ts/app/hero-form.component.html',
539-
'new-hero-button',
538+
+makeExample('forms/ts/app/hero-form.component.html',
539+
'new-hero-button',
540540
'app/hero-form.component.html (New Hero button)')
541541
:marked
542-
+makeExample('forms/ts/app/hero-form.component.ts',
543-
'new-hero-v1',
542+
+makeExample('forms/ts/app/hero-form.component.ts',
543+
'new-hero-v1',
544544
'app/hero-form.component.ts (New Hero method - v1)')(format=".")
545545
:marked
546546
Run the application again, click the *New Hero* button, and the form clears.
547547
The *required* bars to the left of the input box are red, indicating invalid `name` and `power` properties.
548-
That's understandable as these are required fields.
548+
That's understandable as these are required fields.
549549
The error messages are hidden because the form is pristine; we haven't changed anything yet.
550-
550+
551551
Enter a name and click *New Hero* again.
552552
This time we see an error message! Why? We don't want that when we display a new (empty) hero.
553-
553+
554554
Inspecting the element in the browser tools reveals that the *name* input box is no longer pristine.
555555
Replacing the hero *did not restore the pristine state* of the control.
556556
.l-sub-section
@@ -559,26 +559,26 @@ figure.image-display
559559
replacing the entire hero and clearing the `name` property programmatically.
560560
Angular makes no assumptions and leaves the control in its current, dirty state.
561561
:marked
562-
We'll have to reset the form controls manually with a small trick.
562+
We'll have to reset the form controls manually with a small trick.
563563
We add an `active` flag to the component, initialized to `true`. When we add a new hero,
564564
we toggle `active` false and then immediately back to true with a quick `setTimeout`.
565-
+makeExample('forms/ts/app/hero-form.component.ts',
566-
'new-hero',
565+
+makeExample('forms/ts/app/hero-form.component.ts',
566+
'new-hero',
567567
'app/hero-form.component.ts (New Hero method - final)')(format=".")
568568
:marked
569569
Then we bind the form element to this `active` flag.
570-
+makeExample('forms/ts/app/hero-form.component.html',
571-
'form-active',
570+
+makeExample('forms/ts/app/hero-form.component.html',
571+
'form-active',
572572
'app/hero-form.component.html (Form tag)')
573573
:marked
574-
With `NgIf` bound to the `active` flag,
574+
With `NgIf` bound to the `active` flag,
575575
clicking "New Hero" removes the form from the DOM and recreates it in a blink of an eye.
576576
The re-created form is in a pristine state. The error message is hidden.
577577
.l-sub-section
578578
:marked
579579
This is a temporary workaround while we await a proper form reset feature.
580580
:marked
581-
581+
582582
.l-main-section
583583
:marked
584584
## Submit the form with **ngSubmit**
@@ -602,15 +602,15 @@ figure.image-display
602602
:marked
603603
### The NgForm directive
604604
What `NgForm` directive? We didn't add an [NgForm](../api/common/index/NgForm-directive.html) directive!
605-
605+
606606
Angular did. Angular creates and attaches an `NgForm` directive to the `<form>` tag automatically.
607607

608608
The `NgForm` directive supplements the `form` element with additional features.
609609
It holds the controls we created for the elements with `ngModel` directive and `name` attribute
610610
and monitors their properties including their validity.
611611
It also has its own `valid` property which is true only *if every contained
612612
control* is valid.
613-
613+
614614
:marked
615615
Later in the template we bind the button's `disabled` property to the form's over-all validity via
616616
the `heroForm` variable. Here's that bit of markup:
@@ -686,7 +686,7 @@ figure.image-display
686686
- A form component class with a `Component` decorator.
687687
- The `ngSubmit` directive for handling the form submission.
688688
- Template reference variables such as `#heroForm`, `#name` and `#power`.
689-
- The `[(ngModel)]` syntax and a `name` attribute for two-way data binding, validation and change tracking.
689+
- The `[(ngModel)]` syntax and a `name` attribute for two-way data binding, validation and change tracking.
690690
- The reference variable’s `valid` property on input controls to check if a control is valid and show/hide error messages.
691691
- Controlling the submit button's enabled state by binding to `NgForm` validity.
692692
- Custom CSS classes that provide visual feedback to users about invalid controls.
@@ -704,7 +704,7 @@ figure.image-display
704704
.file hero-form.component.ts
705705
.file main.ts
706706
.file node_modules ...
707-
.file typings ...
707+
.file typings ...
708708
.file index.html
709709
.file package.json
710710
.file tsconfig.json
@@ -718,12 +718,12 @@ figure.image-display
718718
forms/ts/app/hero.ts,
719719
forms/ts/app/app.module.ts,
720720
forms/ts/app/app.component.ts,
721-
forms/ts/app/main.ts,
721+
forms/ts/app/main.ts,
722722
forms/ts/index.html,
723723
forms/ts/forms.css`,
724724
'final, final,,,,,',
725725
`hero-form.component.ts,
726-
hero-form.component.html,
726+
hero-form.component.html,
727727
hero.ts,
728728
app.module.ts,
729729
app.component.ts,

public/docs/ts/latest/guide/user-input.jade

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ include ../_util-fns
66
In this chapter we learn to bind to those events using the Angular
77
event binding syntax.
88

9-
<live-example>Run the live example</live-example>.
9+
Run the <live-example></live-example>.
1010

1111
:marked
1212
## Binding to user input events

0 commit comments

Comments
 (0)