11import { Component , OnInit } from '@angular/core' ;
2- import { NgForm , Validators , ControlGroup , Control } from '@angular/common ' ;
2+ import { REACTIVE_FORM_DIRECTIVES , FormGroup , FormControl , Validators } from '@angular/forms ' ;
33import { Router } from '@angular/router' ;
44import { MdButton } from '@angular2-material/button' ;
55import { MdInput } from '@angular2-material/input' ;
@@ -21,19 +21,19 @@ import { UserService } from '../shared/services/user/user.service';
2121 selector : 'register' ,
2222 templateUrl : 'app/register/register.component.html' ,
2323 styleUrls : [ 'app/register/register.component.css' ] ,
24- directives : [ MD_CARD_DIRECTIVES , MdButton , MdInput , MdSpinner ]
24+ directives : [ MD_CARD_DIRECTIVES , MdButton , MdInput , MdSpinner , REACTIVE_FORM_DIRECTIVES ]
2525} )
2626
2727export class RegisterComponent implements OnInit {
2828 title = 'Register' ;
2929 loginLink = '/login' ;
3030 githubLink = 'https://github.com/domfarolino/angular2-login-seed' ;
3131
32- name : Control ;
33- username : Control ;
34- email : Control ;
35- password : Control ;
36- form : ControlGroup ;
32+ name : FormControl ;
33+ username : FormControl ;
34+ email : FormControl ;
35+ password : FormControl ;
36+ form : FormGroup ;
3737
3838 /**
3939 * Boolean used in telling the UI
@@ -56,19 +56,19 @@ export class RegisterComponent implements OnInit {
5656 /**
5757 * Initialize form Controls
5858 */
59- this . name = new Control ( '' , Validators . compose ( [ Validators . required , Validators . minLength ( 2 ) , Validators . maxLength ( 64 ) ] ) ) ;
60- this . username = new Control ( '' , Validators . compose ( [ Validators . required , Validators . minLength ( 2 ) , Validators . maxLength ( 64 ) ] ) ) ;
61- this . email = new Control ( '' , Validators . compose ( [ Validators . required , Validators . pattern ( "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" ) ] ) ) ;
62- this . password = new Control ( '' , Validators . compose ( [ Validators . required , Validators . minLength ( 2 ) , Validators . maxLength ( 32 ) ] ) ) ;
59+ this . name = new FormControl ( '' , Validators . compose ( [ Validators . required , Validators . minLength ( 2 ) , Validators . maxLength ( 64 ) ] ) ) ;
60+ this . username = new FormControl ( '' , Validators . compose ( [ Validators . required , Validators . minLength ( 2 ) , Validators . maxLength ( 64 ) ] ) ) ;
61+ this . email = new FormControl ( '' , Validators . compose ( [ Validators . required , Validators . pattern ( "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" ) ] ) ) ;
62+ this . password = new FormControl ( '' , Validators . compose ( [ Validators . required , Validators . minLength ( 2 ) , Validators . maxLength ( 32 ) ] ) ) ;
6363
6464 /**
6565 * Initialize form
6666 */
67- this . form = new ControlGroup ( {
68- name : this . name ,
69- username : this . username ,
70- email : this . email ,
71- password : this . password
67+ this . form = new FormGroup ( {
68+ ' name' : this . name ,
69+ ' username' : this . username ,
70+ ' email' : this . email ,
71+ ' password' : this . password
7272 } ) ;
7373 }
7474
0 commit comments