Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS unbind equivalent variables

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?

like image 917
Jazzy Avatar asked Jan 12 '14 05:01

Jazzy


1 Answers

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

like image 113
Radim Köhler Avatar answered Sep 20 '22 21:09

Radim Köhler