Before you bind formControlName in HTML you need to define then in you TS, like this:
ngOnInit(): void {
this.registerForm = this.formBuilder.group({
id: ['', Validators.required],
firstName: ['', Validators.required],
email: ['', Validators.email],
// Other fields
});
}
To know more about the validators, check this Validating reactive froms
for the HTML:
<form [formGroup]="registerForm" (ngSubmit)="register()">
<input type="text" placeholder="type your first name" formControlName="firstname">
<input type="email" placeholder="you Email" formControlName="email">
<!--Other fields-->
</form>
Finally to get the form values:
register() {
console.log(this.registerForm.value);
if(this.loginForm.invalid){
return;
}
// Create a User instance with the form value ...
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…