I'm building my first application with AngularJS, but i have run into a little problem.
I got a table where i render every user in users array like below:
<table class="table table-hover">
<thead>
<tr>
<th>#</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Company</th>
<th>Active</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in users">
<td>{[{ user.id }]}</td>
<td>{[{ user.firstname }]}</td>
<td>{[{ user.lastname }]}</td>
<td>{[{ user.email }]}</td>
<td>{[{ user.company }]}</td>
<td>Yes</td>
<td><a href="#modalUpdateUser" ng-click="getUser(user)" data-toggle="modal"><i class="icon-pencil"></i></a></td>
</tr>
</tbody>
</table>
This works perfectly fine, as i have in my controller.js an array $scope.users that gets filled with the users.
The problem is the last Cell with the the ng-click="getUser(user)", which opens a ModalBox and fills the inputs with the existing users data.
$scope.getUser = function(user) {
$scope.user = user;
};
In the ModalBox all the input fields has ng-model="user.firstname" etc. So this ofcourse Binds the input fields in the ModalBox to the user in my table, and instantly changes the data in the table when i change it in the ModalBox.
But what i want is to edit the data in the ModalBox and then only change the user in the table if i press "Save" in the ModalBox.
So my question is, can i take user object from the ng-repeat in my table and hand it over to my $scope.user which is bound to my ModalBox inputs without keeping them all bound together?
Thanks in advance,
- Rasmus Knudsen
Solution The solution was to use angular.Copy to transfer an object without the binding reference. Working example here: http://docs.angularjs.org/guide/forms