Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class DemoFormComponent implements OnInit {
- public form: FormGroup;
- public username: FormControl;
- public password: FormControl;
- public confirmPassword: FormControl;
- public ngOnInit(): void {
- this.username = new FormControl('', [Validators.required, Validators.minLength(4), Validators.maxLength(10)]);
- this.password = new FormControl('', [Validators.required, Validators.minLength(6)]);
- this.confirmPassword = new FormControl('', [Validators.required, confirmPasswordValidator(this.password)]);
- this.password.registerOnChange(() => this.confirmPassword.updateValueAndValidity());
- this.form = new FormGroup({
- 'username': this.username,
- 'password': this.password,
- 'confirmPassword': this.confirmPassword
- });
- }
- public onSubmit(): void {
- if (this.form.valid) {
- console.log('Form is valid!');
- } else {
- console.log('Form is not valid.');
- }
- }
- }
Add Comment
Please, Sign In to add comment