Blame view

src/app/pages/register/register.component.ts 1.57 KB
05b0b5d8   Yarik   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  import {Component, ViewEncapsulation} from '@angular/core';
  import {FormGroup, AbstractControl, FormBuilder, Validators} from '@angular/forms';
  import {EmailValidator, EqualPasswordsValidator} from '../../theme/validators';
  
  import 'style-loader!./register.scss';
  
  @Component({
    selector: 'register',
    templateUrl: './register.html',
  })
  export class Register {
  
    public form:FormGroup;
    public name:AbstractControl;
    public email:AbstractControl;
    public password:AbstractControl;
    public repeatPassword:AbstractControl;
    public passwords:FormGroup;
  
    public submitted:boolean = false;
  
    constructor(fb:FormBuilder) {
  
      this.form = fb.group({
        'name': ['', Validators.compose([Validators.required, Validators.minLength(4)])],
        'email': ['', Validators.compose([Validators.required, EmailValidator.validate])],
        'passwords': fb.group({
          'password': ['', Validators.compose([Validators.required, Validators.minLength(4)])],
          'repeatPassword': ['', Validators.compose([Validators.required, Validators.minLength(4)])]
        }, {validator: EqualPasswordsValidator.validate('password', 'repeatPassword')})
      });
  
      this.name = this.form.controls['name'];
      this.email = this.form.controls['email'];
      this.passwords = <FormGroup> this.form.controls['passwords'];
      this.password = this.passwords.controls['password'];
      this.repeatPassword = this.passwords.controls['repeatPassword'];
    }
  
    public onSubmit(values:Object):void {
      this.submitted = true;
      if (this.form.valid) {
        // your code goes here
        // console.log(values);
      }
    }
  }