I have a page within which there is a (well defined) number of inputs into which the user may enter data (i.e. text boxes, selects, etc.).
Whenever the user fills data and clicks on the SAVE button, a number of manipulations and checks need to take place before the actual SAVE process begins.
Now (and here is the question), whenever the user clicks on a "X" button to close the page, I want to check if data base changed at all (and prompt for confirmation if so).
I generate two objects with the full list of inputs:
Initial values object holding the whole list of values BEFORE being presented to the user (
@scope.Base_Object
), andThe whole list of inputs mapped to the inputs using
ng-model
(@scope.Work_Object
).
Note: Both objects display identical structures which cannot change (i.e. no elements are added/removed).
So, I would expect that comparing JSON.stringify(@scope.Base_Object)
against JSON.stringify(@scope.Work_Object)
should tell me if anything was changed.
Is this method reliable enough?