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

Commit a059ae8

Browse files
docs(reactive-forms): bind option value
1 parent 529b240 commit a059ae8

File tree

7 files changed

+24
-16
lines changed

7 files changed

+24
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ <h3><i>A FormGroup with multiple FormControls</i></h3>
2020
<div class="form-group">
2121
<label class="center-block">State:
2222
<select class="form-control" formControlName="state">
23-
<option *ngFor="let state of states">{{state}}</option>
23+
<option *ngFor="let state of states" [value]="state">{{state}}</option>
2424
</select>
2525
</label>
2626
</div>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ <h4>Secret Lair</h4>
2121
<div class="form-group">
2222
<label class="center-block">State:
2323
<select class="form-control" formControlName="state">
24-
<option *ngFor="let state of states">{{state}}</option>
24+
<option *ngFor="let state of states" [value]="state">{{state}}</option>
2525
</select>
2626
</label>
2727
</div>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ <h3><i>PatchValue to initialize a value</i></h3>
2020
<div class="form-group">
2121
<label class="center-block">State:
2222
<select class="form-control" formControlName="state">
23-
<option *ngFor="let state of states">{{state}}</option>
23+
<option *ngFor="let state of states" [value]="state">{{state}}</option>
2424
</select>
2525
</label>
2626
</div>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ <h3><i>A FormGroup with multiple FormControls</i></h3>
2020
<div class="form-group">
2121
<label class="center-block">State:
2222
<select class="form-control" formControlName="state">
23-
<option *ngFor="let state of states">{{state}}</option>
23+
<option *ngFor="let state of states" [value]="state">{{state}}</option>
2424
</select>
2525
</label>
2626
</div>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ <h4>Address #{{i + 1}}</h4>
3030
<div class="form-group">
3131
<label class="center-block">State:
3232
<select class="form-control" formControlName="state">
33-
<option *ngFor="let state of states">{{state}}</option>
33+
<option *ngFor="let state of states" [value]="state">{{state}}</option>
3434
</select>
3535
</label>
3636
</div>

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
<!-- Hero Detail Controls -->
1313
<!-- #enddocregion buttons -->
1414
<div class="form-group">
15-
<label>Name:</label>
16-
<input class="form-control" formControlName="name">
15+
<label>Name:
16+
<input class="form-control" formControlName="name">
17+
</label>
1718
</div>
1819

1920
<div formArrayName="secretLairs" class="well well-lg">
@@ -22,22 +23,26 @@
2223
<h4>Address #{{i + 1}}</h4>
2324
<div style="margin-left: 1em;">
2425
<div class="form-group">
25-
<label>Street:</label>
26-
<input class="form-control" formControlName="street">
26+
<label>Street:
27+
<input class="form-control" formControlName="street">
28+
</label>
2729
</div>
2830
<div class="form-group">
2931
<label>City:</label>
30-
<input class="form-control" formControlName="city">
32+
<input class="form-control" formControlName="city">
33+
</label>
3134
</div>
3235
<div class="form-group">
33-
<label>State:</label>
34-
<select class="form-control" formControlName="state">
35-
<option *ngFor="let state of states">{{state}}</option>
36-
</select>
36+
<label>State:
37+
<select class="form-control" formControlName="state">
38+
<option *ngFor="let state of states" [value]="state">{{state}}</option>
39+
</select>
40+
</label>
3741
</div>
3842
<div class="form-group">
39-
<label>Zip Code:</label>
40-
<input class="form-control" formControlName="zip">
43+
<label>Zip Code:
44+
<input class="form-control" formControlName="zip">
45+
</label>
4146
</div>
4247
</div>
4348
<br>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,9 @@ figure.image-display
465465
The revised template includes more text inputs, a select box for the `state`, radio buttons for the `power`,
466466
and a checkbox for the `sidekick`.
467467

468+
You must bind the option's value property with `[value]="state"`.
469+
If you do not bind the value, the select shows the first option form the data model.
470+
468471
The component _class_ defines control properties without regard for their representation in the template.
469472
You define the `state`, `power`, and `sidekick` controls the same way you defined the `name` control.
470473
You tie these controls to the template HTML elements in the same way,

0 commit comments

Comments
 (0)