Working on a form for a user to edit their details based on a variable on the $rootScope (could also be $scope).
$rootScope.formData = $rootScope.user;
In the view, there is an ng-model on the input:
ng-model="formData.email"
The behavior I expect is to update the model and only $rootScope.formData will update, but instead, both update.
Is there a way to break the relationship between the two?
As discussed in the comments, we are working with JS references. That means, that we are passing the user
as reference to the other (root) scope
We can call angular.copy()
or cloneDeep()
(see lo-dash) to work with a new instance
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With