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

Commit 9a063da

Browse files
docs(reactive-forms): add checkbox and radio buttons
1 parent 6f7ce7a commit 9a063da

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

public/docs/_examples/reactive-forms/ts/app/hero-detail-4.component.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,17 @@ <h3><i>A FormGroup with multiple FormControls</i></h3>
2424
<label>Zip Code:</label>
2525
<input class="form-control" formControlName="zip">
2626
</div>
27+
<div class="form-group">
28+
<label>Super power:</label>
29+
<input type="radio" formControlName="power" value="flight">Flight
30+
<input type="radio" formControlName="power" value="x-ray vision">X-ray vision
31+
<input type="radio" formControlName="power" value="strength">Strength
32+
</div>
33+
<div class="checkbox">
34+
<label>
35+
<input type="checkbox" formControlName="sidekick">I have a sidekick.</label>
36+
</div>
2737
</form>
38+
39+
40+
<p>Form value: {{ heroForm.value | json }}</p>

public/docs/_examples/reactive-forms/ts/app/hero-detail-4.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export class HeroDetailComponent4 {
2626
street: '',
2727
city: '',
2828
state: '',
29-
zip: ''
29+
zip: '',
30+
power: '',
31+
sidekick: ''
3032
});
3133
}
3234
}

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ a#intro
8989
You don't push and pull data values. Angular handles that for you with `ngModel`.
9090
Angular updates the mutable _data model_ with user changes as they happen.
9191

92-
When writing in a reactive style, you rarely, if ever, use two-way data binding.
92+
For this reason, the `ngModel` directive is not part of the ReactiveFormsModule.
9393

9494
These differences reflect two architectural paradigms,
9595
with their own strengths and weaknesses,
@@ -398,7 +398,8 @@ figure.image-display
398398

399399
:marked
400400
### More FormControls
401-
A hero has more than a name. A hero has an address too. You already have address data
401+
A hero has more than a name. A hero has an address, a super
402+
power and sometimes a sidekick too. You already have address data
402403
in `data-model.ts`, so add it to the imports so you can use it:
403404

404405
+makeExample('reactive-forms/ts/app/hero-detail-4.component.ts', 'imports','app/hero-detail.component.ts (excerpt)')(format=".")
@@ -418,12 +419,24 @@ figure.image-display
418419

419420
.alert.is-helpful
420421
:marked
421-
*Reminder*: Ignore the many mentions of `form-group` and `form-control`in this markup.
422+
*Reminder*: Ignore the many mentions of `form-group`,
423+
`form-control`, and `checkbox` in this markup.
422424
Those are _bootstrap_ CSS classes that Angular itself ignores.
423425
Pay attention to the `formGroupName` and `formControlName` attributes.
424426
They are the Angular directives that bind the HTML controls to the
425427
Angular `FormGroup` and `FormControl` properties in the component class.
426428

429+
:marked
430+
These new `FormControls` include text inputs, a select for the state,
431+
radio buttons, and a checkbox. In the class
432+
they are instantiated in the same way and in the template,
433+
each one is tied to the form control tree by specifiying
434+
the `FormControl` name using the `formControlName` directive.
435+
For more information about radio buttons, selects, and checkboxes,
436+
see the API reference for [RadioControlValueAccessor](api/forms/index/RadioControlValueAccessor-directive.html),
437+
[SelectControlValueAccessor](api/forms/index/SelectControlValueAccessor-directive.html),
438+
and [CheckboxControlValueAccessor](api/forms/index/CheckboxControlValueAccessor-directive.html).
439+
427440
.l-main-section
428441
a#grouping
429442
:marked

0 commit comments

Comments
 (0)