How to push the roles form data value to createUserForm data value so that they will become 1 object ?
#The final result should look like this
{
"emailAddress": "[email protected]",
"firstName": "sdsfd",
"lastName": "fsdfsdf",
"phoneNumber": "21324",
"companyName": "sdfsdf",
"title": "CEO",
"roleId": 7,
"associatedAccount": "WALLS",
"accountId": 4,
"roles": [
{
"id": 12,
"name": "Architect",
"isShow": true,
"transactionRoleId": 12
},
{
"id": 11,
"name": "Construction Project Director",
"isShow": true,
"transactionRoleId": 11
},
{
"id": 9,
"name": "COVP",
"isShow": true,
"transactionRoleId": 9
}
]
}
This is the data from roles when I submit
{
"id": 12,
"name": "Architect",
"isShow": true,
"transactionRoleId": 12
}
This is the data from createUserForm when I submit
{
"emailAddress": "adasd",
"firstName": "asdasdasd",
"lastName": "asdasd",
"phoneNumber": "2132",
"companyName": "adasdas",
"title": "dasdasdas",
"roleId": 7,
"associatedAccount": "test",
"accountId": 4
}
--->>> another form
roles = new FormControl();
--->>>> User Form
createUserForm = new FormGroup({
emailAddress: new FormControl(),
firstName: new FormControl(),
lastName: new FormControl(),
phoneNumber: new FormControl(),
companyName: new FormControl(),
title: new FormControl(),
roleId: new FormControl(),
associatedAccount: new FormControl(),
accountId: new FormControl(),
});
--->>> what i tried
saveUser() {
this.createUserForm.get('roleId').setValue(7);
console.log("this.createUserForm.value" , this.createUserForm.value)
console.log("data" ,this.roles.value)
console.log("finaldata : " ,
this.createUserForm.value.push(this.roles.value))
rolesas aformArrayinside thecreateUserFormthis will do what you need out of the box, but somehow you have both separate andthis.roles.valuehas the value which you need and only want to merge it withthis.createUserForm.valuethen you can simply use this approachconst formValues = { ...this.createUserForm.value, roles: this.roles.value }