Guest User

Untitled

a guest
Mar 14th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. export class DemoFormComponent implements OnInit {
  2. public form: FormGroup;
  3. public username: FormControl;
  4. public password: FormControl;
  5. public confirmPassword: FormControl;
  6.  
  7. public ngOnInit(): void {
  8. this.username = new FormControl('', [Validators.required, Validators.minLength(4), Validators.maxLength(10)]);
  9. this.password = new FormControl('', [Validators.required, Validators.minLength(6)]);
  10. this.confirmPassword = new FormControl('', [Validators.required, confirmPasswordValidator(this.password)]);
  11.  
  12. this.password.registerOnChange(() => this.confirmPassword.updateValueAndValidity());
  13.  
  14. this.form = new FormGroup({
  15. 'username': this.username,
  16. 'password': this.password,
  17. 'confirmPassword': this.confirmPassword
  18. });
  19. }
  20.  
  21. public onSubmit(): void {
  22. if (this.form.valid) {
  23. console.log('Form is valid!');
  24. } else {
  25. console.log('Form is not valid.');
  26. }
  27. }
  28. }
Add Comment
Please, Sign In to add comment