I am confused about FormGroup.
The class has these properties:
formValue!: FormGroup;
employeeModelObj: EmployeeModel = new EmployeeModel();
employeeData!: any;
and in the ngOnit it has:
ngOnInit(): void {
this.formValue = this.formBuilder.group({
firstName: [''],
lastName: [''],
emailId: [''],
phoneNumber: [''],
salary: [''],
});
}
and when adding new employee details it has this
postEmployeeDetails() {
this.employeeModelObj.firstName = this.formValue.value.firstName;
this.employeeModelObj.lastName = this.formValue.value.lastName;
this.employeeModelObj.emailId = this.formValue.value.emailId;
this.employeeModelObj.phoneNumber = this.formValue.value.phoneNumber;
this.employeeModelObj.salary = this.formValue.value.salary;
}
Sorry I cannot figure out on my own but what is the point of assigning FormGroup class to formValue property? And why do we have to create a employeeModelObj and assign the values to it?
And what does formBuilder.group do? and why does are we assigning formValue to it with initilization of nothing?
this.employeeModelObj = this.formValue.valuedoesn't work ? Or withas MyType?