Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { HttpService } from '../services/http-service';
- import { Component, OnInit } from '@angular/core';
- import { FormControl, FormGroupDirective, NgForm, Validators, FormGroup, FormBuilder } from '@angular/forms';
- import {ErrorStateMatcher} from '@angular/material/core';
- export class MyErrorStateMatcher implements ErrorStateMatcher {
- isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
- const invalidCtrl = !!(control && control.invalid && control.parent.dirty);
- const invalidParent = !!(control && control.parent && control.parent.invalid && control.parent.dirty);
- return (invalidCtrl || invalidParent);
- }
- }
- @Component({
- selector: 'app-register',
- templateUrl: './register.component.html',
- styleUrls: ['./register.component.css']
- })
- export class RegisterComponent implements OnInit {
- name: string;
- surname: string;
- email: string;
- password: string;
- phonenumber: number;
- passwordFormGroup: FormGroup;
- matcherpass = new MyErrorStateMatcher();
- matcher = new ErrorStateMatcher();
- constructor(private formBuilder: FormBuilder, private httpService: HttpService) {
- this.passwordFormGroup = this.formBuilder.group({
- password: ['', [Validators.required, Validators.minLength(9)]],
- confirmPassword: ['']
- }, { validator: this.checkPasswords });
- }
- nameFormControl = new FormControl('', [
- Validators.required,
- ]);
- surnameFormControl = new FormControl('', [
- Validators.required,
- ]);
- emailFormControl = new FormControl('', [
- Validators.required,
- Validators.email,
- ]);
- passwordFormControl = new FormControl('', [
- Validators.required,
- Validators.minLength(8)
- ]);
- phoneNumberFormControl = new FormControl('', [
- Validators.required,
- Validators.minLength(9),
- Validators.maxLength(9)
- ]);
- statuteFormControl = new FormControl('', [
- Validators.required,
- ]);
- ngOnInit() {
- }
- checkPasswords(group: FormGroup) {
- const pass = group.controls.password.value;
- const confirmPass = group.controls.confirmPassword.value;
- return pass === confirmPass ? null : { notSame: true };
- }
- addUser() {
- this.httpService.addUser(this.name, this.surname, this.email, this.password, this.phonenumber).subscribe(user => {
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement