[Solved] Modal problem

Hi,

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?

there is peace of code:

Thanks for the reproduction example, that is super helpful.

Does this example behave as you would expect: Ionic Docs Example (forked) - StackBlitz?

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).

Here is a little more information about pass by reference in Javascript: link.

1 Like

Thank you! Your example doing exactly what I have tried to achieve.