Advertisement
Guest User

Untitled

a guest
Jan 9th, 2019
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. import { HttpService } from '../services/http-service';
  2. import { Component, OnInit } from '@angular/core';
  3. import { FormControl, FormGroupDirective, NgForm, Validators, FormGroup, FormBuilder } from '@angular/forms';
  4. import {ErrorStateMatcher} from '@angular/material/core';
  5.  
  6. export class MyErrorStateMatcher implements ErrorStateMatcher {
  7. isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
  8. const invalidCtrl = !!(control && control.invalid && control.parent.dirty);
  9. const invalidParent = !!(control && control.parent && control.parent.invalid && control.parent.dirty);
  10.  
  11. return (invalidCtrl || invalidParent);
  12. }
  13. }
  14.  
  15.  
  16. @Component({
  17. selector: 'app-register',
  18. templateUrl: './register.component.html',
  19. styleUrls: ['./register.component.css']
  20. })
  21. export class RegisterComponent implements OnInit {
  22.  
  23. name: string;
  24. surname: string;
  25. email: string;
  26. password: string;
  27. phonenumber: number;
  28.  
  29. passwordFormGroup: FormGroup;
  30.  
  31. matcherpass = new MyErrorStateMatcher();
  32. matcher = new ErrorStateMatcher();
  33.  
  34. constructor(private formBuilder: FormBuilder, private httpService: HttpService) {
  35. this.passwordFormGroup = this.formBuilder.group({
  36. password: ['', [Validators.required, Validators.minLength(9)]],
  37. confirmPassword: ['']
  38. }, { validator: this.checkPasswords });
  39.  
  40. }
  41.  
  42.  
  43. nameFormControl = new FormControl('', [
  44. Validators.required,
  45. ]);
  46.  
  47. surnameFormControl = new FormControl('', [
  48. Validators.required,
  49. ]);
  50.  
  51. emailFormControl = new FormControl('', [
  52. Validators.required,
  53. Validators.email,
  54. ]);
  55.  
  56. passwordFormControl = new FormControl('', [
  57. Validators.required,
  58. Validators.minLength(8)
  59. ]);
  60.  
  61. phoneNumberFormControl = new FormControl('', [
  62. Validators.required,
  63. Validators.minLength(9),
  64. Validators.maxLength(9)
  65. ]);
  66.  
  67. statuteFormControl = new FormControl('', [
  68. Validators.required,
  69. ]);
  70.  
  71.  
  72. ngOnInit() {
  73. }
  74.  
  75. checkPasswords(group: FormGroup) {
  76. const pass = group.controls.password.value;
  77. const confirmPass = group.controls.confirmPassword.value;
  78.  
  79. return pass === confirmPass ? null : { notSame: true };
  80. }
  81.  
  82. addUser() {
  83. this.httpService.addUser(this.name, this.surname, this.email, this.password, this.phonenumber).subscribe(user => {
  84. });
  85. }
  86.  
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement