My current challenge involves handling an HTML form that is connected to an object named a
through an ngModel
. When a user updates the data in the form, I send a PUT request to update the resource on the server. The response from the server contains updated information such as lastModified
, which needs to be synchronized with my local data.
The issue arises when I try to replace the object entirely using a = b
(where b
represents the server response). This approach triggers a complete re-render of the HTML form because ngModel
treats it as an entirely new object. As a result, if a user has an active input field, they lose focus when the form refreshes.
To avoid this re-rendering problem, I have created a function that recursively adjusts the keys in the a
object while preserving all references. However, I suspect that this may not be the best solution. Is this a common issue in Angular? Are there alternative approaches to handle this situation effectively? Or am I approaching this problem incorrectly?
Update: It's worth noting that my form does not use ngModel
. Instead, it is part of an iteration element within an ngRepeat
.