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

Commit 6f27f3d

Browse files
docs(reactive-forms): add code for Validators.required
1 parent 88af223 commit 6f27f3d

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

public/docs/_examples/reactive-forms/ts/app/demo.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { HeroDetailComponent4 } from './hero-detail-4.component';
1111
import { HeroDetailComponent5 } from './hero-detail-5.component';
1212
import { HeroDetailComponent6 } from './hero-detail-6.component';
1313
import { HeroDetailComponent7 } from './hero-detail-7.component';
14+
// import { Something } from './hero-detail-1.component';
1415

1516
@NgModule({
1617
imports: [
@@ -25,7 +26,7 @@ import { HeroDetailComponent7 } from './hero-detail-7.component';
2526
HeroDetailComponent4,
2627
HeroDetailComponent5,
2728
HeroDetailComponent6,
28-
HeroDetailComponent7 ],
29+
HeroDetailComponent7],
2930
bootstrap: [ DemoComponent ]
3031
})
3132
export class DemoModule { }

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ <h3><i>FormGroup with a single FormControl</i></h3>
1010

1111

1212
<!--<input formControlName="name1">-->
13-
<input [formControl]="ctrl">
13+
<!--<input [formControl]="ctrl">-->
14+
1415
<!-- #enddocregion basic-form-->

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ export class HeroDetailComponent1 {
1515
name: new FormControl()
1616
});
1717
// This requires a FormGroup
18-
simpleFormControl = new FormControl({
19-
name1: ''
20-
})
18+
// simpleFormControl = new FormControl({
19+
// name1: ''
20+
// })
2121
}
2222
// This one causes: Cannot find control with unspecified name attribute
23-
export class Something {
24-
ctrl = new FormControl()
25-
}
23+
// export class Something {
24+
// ctrl = new FormControl()
25+
// }
2626
// #enddocregion v1

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ <h3><i>A FormGroup with a single FormControl using FormBuilder</i></h3>
1111

1212
<!-- #docregion form-value-json -->
1313
<p>Form: {{ heroForm.value | json }}</p>
14+
<p>Form status: {{ heroForm.status }}</p>
15+
<p>Name status: {{ heroForm.get('name').status}}</p>
1416
<!-- #enddocregion form-value-json -->

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* tslint:disable:component-class-suffix */
22
// #docregion imports
33
import { Component } from '@angular/core';
4-
import { FormBuilder, FormGroup } from '@angular/forms';
4+
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
55
// #enddocregion imports
66

77
@Component({
@@ -19,7 +19,7 @@ export class HeroDetailComponent2 {
1919

2020
createForm() {
2121
this.heroForm = this.fb.group({
22-
name: '', // <--- the FormControl called "name"
22+
name: ['', Validators.required ], // <--- the FormControl called "name"
2323
});
2424
}
2525
}

0 commit comments

Comments
 (0)