I am facing an issue with setting data to the form array in my project. The scenario is that when filling out user details, some users have multiple addresses.
Here is User.ts
export interface User {
id?: number;
name: string;
age: number;
address: MyAddress;
}
MyAddress.ts
export interface MyAddress {
id?: number;
line1: string;
line2: string;
postalCode: string;
city: string;
}
Inside component.ts file
myForm = this.formBuilder.group({
name: ['', Validators.required],
age: ['', Validators.required]
});
myFormAddress = this.formBuilder.group({
address: this.formBuilder.array([]),
});
setDetail(): User {
let myObj = new User();
myObj.name = this.myForm.controls.name.getRawValue();
myObj.age = this.myForm.controls.description.getRawValue();
myObj.address = {
//need to set form array data here
}
return myObj;
}