Skip to content

Instantly share code, notes, and snippets.

@zainzafar90
Created November 30, 2018 13:18
Show Gist options
  • Save zainzafar90/307fc05f8715302770b2c10b5f05c0bc to your computer and use it in GitHub Desktop.
Save zainzafar90/307fc05f8715302770b2c10b5f05c0bc to your computer and use it in GitHub Desktop.
export class AppComponent implements OnInit {
myForm: FormGroup;
submitted = false;
constructor(private formBuilder: FormBuilder) {}
ngOnInit() {
this.myForm = this.formBuilder.group({
email: ['', [Validators.required, Validators.email]],
password: [
'',
[Validators.required, Validators.minLength(6), Validators.maxlength(20)]
]
});
}
get formControls() {
return this.myForm.controls;
}
onSubmit() {
this.submitted = true;
if (this.myForm.invalid) {
return;
}
alert(
'New user successfully registered \n' + JSON.stringify(this.myForm.value)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment