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

Commit 8d99a69

Browse files
makeExample updates
1 parent e839034 commit 8d99a69

File tree

2 files changed

+53
-31
lines changed

2 files changed

+53
-31
lines changed

public/docs/_examples/reactive-forms/ts/app/hero-signup-versions.component.ts

+40-21
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ export class HeroSignUpComponent1 {
2929
})
3030
// #docregion v2
3131
export class HeroSignUpComponent2 {
32+
form: FormGroup; // <--- form is of type FormGroup
33+
constructor(private _fb: FormBuilder) { // <--- inject FormBuilder
34+
this.form = this._fb.group({ // <--- make this.form a FormBuilder group
35+
name: '',
36+
username: '',
37+
password: '',
38+
confirm: ''
39+
});
40+
}
41+
}
42+
// #enddocregion v2
43+
44+
@Component({
45+
moduleId: module.id,
46+
selector: 'hero-signup-3',
47+
templateUrl: './hero-signup-3.component.html'
48+
})
49+
// #docregion v3
50+
export class HeroSignUpComponent3 {
3251
form: FormGroup;
3352
constructor(private _fb: FormBuilder) {
3453
this.form = this._fb.group({
@@ -43,15 +62,15 @@ export class HeroSignUpComponent2 {
4362
});
4463
}
4564
}
46-
// #enddocregion v2
65+
// #enddocregion v3
4766

4867
@Component({
4968
moduleId: module.id,
50-
selector: 'hero-signup-3',
51-
templateUrl: './hero-signup-3.component.html'
69+
selector: 'hero-signup-4',
70+
templateUrl: './hero-signup-4.component.html'
5271
})
53-
// #docregion v3
54-
export class HeroSignUpComponent3 {
72+
// #docregion v4
73+
export class HeroSignUpComponent4 {
5574
form: FormGroup;
5675
constructor(private _fb: FormBuilder) {
5776
this.form = this._fb.group({
@@ -62,16 +81,16 @@ export class HeroSignUpComponent3 {
6281
});
6382
}
6483
}
65-
// #enddocregion v3
84+
// #enddocregion v4
6685

6786

6887
@Component({
6988
moduleId: module.id,
70-
selector: 'hero-signup-4',
71-
templateUrl: './hero-signup-4.component.html'
89+
selector: 'hero-signup-5',
90+
templateUrl: './hero-signup-5.component.html'
7291
})
73-
// #enddocregion v4
74-
export class HeroSignUpComponent4 {
92+
// #enddocregion v5
93+
export class HeroSignUpComponent5 {
7594
form: FormGroup;
7695
constructor(private _fb: FormBuilder) {
7796
this.form = this._fb.group({
@@ -88,15 +107,15 @@ export class HeroSignUpComponent4 {
88107
});
89108
}
90109
}
91-
// #enddocregion v4
110+
// #enddocregion v5
92111

93112
@Component({
94113
moduleId: module.id,
95-
selector: 'hero-signup-5',
96-
templateUrl: './hero-signup-5.component.html'
114+
selector: 'hero-signup-6',
115+
templateUrl: './hero-signup-6.component.html'
97116
})
98-
// #docregion v5
99-
export class HeroSignUpComponent5 {
117+
// #docregion v6
118+
export class HeroSignUpComponent6 {
100119
form: FormGroup;
101120
constructor(private _fb: FormBuilder) {
102121
this.form = this._fb.group({
@@ -117,15 +136,15 @@ export class HeroSignUpComponent5 {
117136
});
118137
}
119138
}
120-
// #enddocregion v5
139+
// #enddocregion v6
121140

122141
@Component({
123142
moduleId: module.id,
124-
selector: 'hero-signup-6',
125-
templateUrl: './hero-signup-6.component.html'
143+
selector: 'hero-signup-7',
144+
templateUrl: './hero-signup-7.component.html'
126145
})
127-
// #docregion v6
128-
export class HeroSignUpComponent6 {
146+
// #docregion v7
147+
export class HeroSignUpComponent7 {
129148
form: FormGroup;
130149
constructor(private _fb: FormBuilder) {
131150
this.form = this._fb.group({
@@ -155,7 +174,7 @@ export class HeroSignUpComponent6 {
155174
});
156175
}
157176
}
158-
// #enddocregion v6
177+
// #enddocregion v7
159178

160179
export const components = [
161180
HeroSignUpComponent1,

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

+13-10
Original file line numberDiff line numberDiff line change
@@ -126,25 +126,28 @@ a#formbuilder
126126
`FormBuilder` is a class that helps reduce repetition and clutter by doing some of the heavy lifting behind the scenes.
127127
You've already imported `FormBuilder` into `hero-signup.component.ts`.
128128

129-
To take advantage of `FormBuilder`, `HeroSignUpComponent` needs refactoring. In the component class, let Angular know that `form` is of type `FormGroup`. Then use the constructor method and inject `FormBuilder` with `constructor(public fb: FormBuilder)`. Inside the constructor, you can use `FormBuilder` to set the `form` as a `FormBuilder` group which lets you instantiate the **FormControls** by simply using the `formControlName` and in this case, an empty value. In this way, `FormBuilder` instantiates each `FormControl` for you, reducing repetitive code. Now, you don't have to use `new` over and over.
129+
To take advantage of `FormBuilder`, `HeroSignUpComponent` needs refactoring. In the component class, let Angular
130+
know that `form` is of type `FormGroup`.
131+
132+
Then use the constructor method and inject `FormBuilder` with
133+
`constructor(public fb: FormBuilder)`. Inside the constructor, you can use `FormBuilder` to set the
134+
`form` as a group, which lets you instantiate the **FormControls** by simply using the `formControlName`
135+
and in this case, an empty value. In this way, `FormBuilder` instantiates each `FormControl` for you,
136+
reducing repetitive code. Now, you don't have to use `new` over and over.
130137

131138
+makeExample('reactive-forms/ts/app/hero-signup-versions.component.ts', 'v2','app/hero-signup.component.ts (excerpt)')(format=".")
132139

133140
:marked
134-
lkdjf
135-
136-
+makeExample('reactive-forms/ts/app/hero-signup.component.1.ts', 'class-refactor','app/hero-signup.component.ts (excerpt)')(format=".")
137-
138-
:marked
139-
This form looks great, but are the model and template talking? To inspect what’s going on, add this after the closing form tag in app.component.html:
141+
This form looks great, but are the model and template talking? To inspect what’s going on, add this after the
142+
closing form tag in `app.component.html`:
140143

141144
+makeExample('reactive-forms/ts/app/hero-signup.component.html', 'form-value-json','app/hero-signup.component.html')(format=".")
142145

143146
:marked
144-
This outputs the value of the form in JSON in the browser.
147+
This outputs the value of the form in JSON in the browser:
145148

146149
figure.image-display
147-
img(src="/resources/images/devguide/app/json-output1.png" width="400px" alt="JSON output")
150+
img(src="/resources/images/devguide/reactive-forms/json-output1.png" width="400px" alt="JSON output")
148151

149152
:marked
150153
Type a value into any of the inputs to see the value update dynamically.
@@ -156,7 +159,7 @@ figure.image-display
156159
a#grouping
157160
:marked
158161
## Grouping FormControls
159-
In the component class add some address FormControls as below.
162+
In the component class add some address **FormControls** as below.
160163

161164
+makeExample('reactive-forms/ts/app/hero-signup.component.1.ts', 'add-form-controls','app/hero-signup.component.ts (excerpt)')(format=".")
162165

0 commit comments

Comments
 (0)