I have a component it uses a reactive form and an angular grid. I am loading data in the form and in the grid. The data is editable and the user can click a button save and store it.
Unfortunately the form knows nothing about the data of the grid. If the form would know the data of the grid I could get the whole data by this.myFormGroup.value and I could known if there are changes by this.myForm.valueChanges (in the form and in the grid).
I am doing that to get the form data and to know if the form data has changes. But separately I am getting the data of the grid via forEachNode and the events cellValueChanged + rowDataUpdated.
Which strategy are you using to detect changes on components with reactive forms and angular grid and to send the data in backend? I am sure, there is a straightforward way.
Update:
I want to load a model (data) from backend and bind the model to a reactive form.
Original model from backend:
{
"firstName":"Paul",
"lastName":"Smith",
"address":{
"street":"228 Park Ave S",
"city":"New York",
"state":"USA",
"zip":"10003"
},
"gridData":[{'empId': 'A1', 'empName': 'A', 'skill': 'A'}]
}
The user makes changes and when the user saves the changes I want to take the updated model like this.myForm.value. It returns directly my model bound to the form. I would like that the rows of the grid are also included in the bound model returned when I am calling this.myForm.value.
Model updated:
{
"firstName":"John",
"lastName":"Smith",
"address":{
"street":"18 Green Aloyse S",
"city":"New York",
"state":"USA",
"zip":"2222"
},
"gridData":[{'empId': 'A1', 'empName': 'A', 'skill': 'A'},
{'empId': 'A1', 'empName': 'A', 'skill': 'A'},
{'empId': 'B1', 'empName': 'B', 'skill': 'B'},
{'empId': 'C1', 'empName': 'C', 'skill': 'C'},
]
}
How do you build the updated model that will be send to the Server?
this.myForm.value. It returns directly my model bound to the form. I would like that the rows of the grid are also included in the bound model returned when I am callingthis.myForm.value. What are you doing in this case? It is a very typical case.... - MrScf