I have interesting problem and can’t figure out how to work around it.
the goal is simple to edit existing data in modal window. When the data is changed need to press save and data should updates only in that way.
I have created the modal in ionic with angular and input inside. When I changing anything in modal, the data in parent window changes as well without confirmation.
May somebody have any idea, how to fix it?
By reworking the data flow a little bit, we can prevent direct mutations to the data object you are passing around. Objects are pass by reference, so when you are mutating the name property with ngModel binding, it is replacing the original value of that property.
If we clone the property value instead to your local member newName, we can make mutations to that reference and decide if we want to persist those changes back to your data object (when the modal is confirmed) or discard the changes (modal is dismissed).