11import { Component } from '@angular/core' ;
2- import { FormBuilder , FormGroup , Validators } from '@angular/forms' ;
2+ import { FormArray , FormBuilder , FormControl , FormGroup , Validators } from '@angular/forms' ;
3+ import { DateRange , IRangeSliderValue } from 'igniteui-angular' ;
34
5+
6+ export interface User {
7+ date : FormControl < string | Date | null > ,
8+ time : FormControl < string | Date | null > ,
9+ email : FormControl < string | null > ,
10+ fullName : FormControl < string | null > ,
11+ movie : FormControl < string | null > ,
12+ phone : FormControl < number | null > ,
13+ rating : FormControl < number | null > ,
14+ checkbox : FormControl < boolean | null > ,
15+ radio : FormControl ,
16+ switch : FormControl < boolean | null > ,
17+ range : FormControl < DateRange | null > ,
18+ slider : FormControl < IRangeSliderValue | null >
19+ calendar : FormControl < string | Date | null >
20+ month : FormControl < string | Date | null >
21+ genres : FormControl < string [ ] | null >
22+ }
423@Component ( {
524 selector : 'app-reactive-form' ,
625 styleUrls : [ './reactive-forms.component.scss' ] ,
726 templateUrl : './reactive-forms.component.html'
827} )
928export class ReactiveFormsSampleComponent {
1029 public genres = [ ] ;
11- public user : FormGroup ;
1230 public minTime = '06:15:30' ;
1331 public maxTime = '09:15:30' ;
32+ public minValue = '0' ;
33+ public maxValue = '100' ;
1434 public minDate = new Date ( ) ;
1535 public maxDate = new Date ( new Date ( this . minDate . getFullYear ( ) , this . minDate . getMonth ( ) , this . minDate . getDate ( ) + 14 ) ) ;
36+ public user : FormGroup < User > ;
1637
17-
18- constructor ( fb : FormBuilder ) {
19- this . user = fb . group ( {
20- date : [ '' , Validators . required ] ,
21- time : [ '' , Validators . required ] ,
22- email : [ '' , Validators . required ] ,
23- fullName : [ '' , Validators . required ] ,
24- genres : [ '' ] ,
25- movie : [ '' , Validators . required ] ,
26- phone : [ '' ]
38+ constructor ( ) {
39+ this . user = new FormGroup < User > ( {
40+ date : new FormControl ( '' , Validators . required ) ,
41+ time : new FormControl ( '' , Validators . required ) ,
42+ email : new FormControl ( '' , [ Validators . required , Validators . email ] ) ,
43+ fullName : new FormControl ( '' , [ Validators . required , Validators . pattern ( / ^ [ \p{ L} \p{ M} ' \- ] + $ / u) ] ) ,
44+ movie : new FormControl ( '' , Validators . required ) ,
45+ phone : new FormControl ( null , Validators . required ) ,
46+ rating : new FormControl ( 2 , Validators . required ) ,
47+ checkbox : new FormControl ( true , Validators . required ) ,
48+ radio : new FormControl ( '' ) ,
49+ switch : new FormControl ( false ) ,
50+ range : new FormControl ( { start : new Date ( ) , end : new Date ( new Date ( ) . setDate ( new Date ( ) . getDate ( ) + 5 ) ) } ) ,
51+ slider : new FormControl ( { lower : 5 , upper : 30 } ) ,
52+ calendar : new FormControl ( null ) ,
53+ month : new FormControl ( null ) ,
54+ genres : new FormControl ( [ 'Action' , 'Adventure' , 'Comedy' ] )
2755 } ) ;
28-
2956 this . genres = [
3057 { type : 'Action' , movies : [ 'The Matrix' , 'Kill Bill: Vol.1' , 'The Dark Knight Rises' ] } ,
3158 { type : 'Adventure' , movies : [ 'Interstellar' , 'Inglourious Basterds' , 'Inception' ] } ,
32- {
33- type : 'Comedy' , movies : [ 'Wild Tales' , 'In Bruges' , 'Three Billboards Outside Ebbing, Missouri' ,
34- 'Untouchable' , '3 idiots' ]
35- } ,
59+ { type : 'Comedy' , movies : [ 'Wild Tales' , 'In Bruges' , 'Three Billboards Outside Ebbing, Missouri' , 'Untouchable' , '3 idiots' ] } ,
3660 { type : 'Crime' , movies : [ 'Training Day' , 'Heat' , 'American Gangster' ] } ,
3761 { type : 'Drama' , movies : [ 'Fight Club' , 'A Beautiful Mind' , 'Good Will Hunting' , 'City of God' ] } ,
3862 { type : 'Biography' , movies : [ 'Amadeus' , 'Bohemian Rhapsody' ] } ,
@@ -43,6 +67,17 @@ export class ReactiveFormsSampleComponent {
4367 { type : 'Thriller' , movies : [ 'The Usual Suspects' ] } ,
4468 { type : 'Western' , movies : [ 'Django Unchained' ] }
4569 ] ;
70+
71+ }
72+
73+ public get email ( ) {
74+ return this . user . get ( 'email' ) ;
75+ }
76+ public get phone ( ) {
77+ return this . user . get ( 'phone' ) ;
78+ }
79+ public get fullName ( ) {
80+ return this . user . get ( 'fullName' ) ;
4681 }
4782
4883 public onSubmit ( ) {
0 commit comments