Reputation: 1907
I am using a modal popup to edit a row in grid view. I am able to retrieve the row values in the modal using row.getProperty() function. But the issue is when I try to edit a value in modal, the value also changes in the background view simultaneously before clicking on the update button.
Upvotes: 0
Views: 520
Reputation: 52867
I am guessing that you are using the same object reference to bind to your modal view and your static background view.
To fix this, you can create a copy of your object in your modal:
In your Modal, use $scope.copy = angular.copy(obj);
to bind a copy of your object to the scope.
After you submit, use angular.extend(obj, copy);
to re-assign the properties back to your original object.
[EDIT]
Using angular.copy to assign the copy back to the original obj would also work and would be preferable over extend:
$scope.obj = angular.copy(copy, obj);
Upvotes: 1
Reputation: 25565
If you don't want the ends to take effect immediately, you need to copy your model and edit the copied version. Once the user clicks the update button, you can move the copied values to the original model.
function Controller($scope) {
$scope.master= {};
$scope.update = function(user) {
// Example with 1 argument
$scope.master= angular.copy(user);
};
$scope.reset = function() {
// Example with 2 arguments
angular.copy($scope.master, $scope.user);
};
$scope.reset();
}
See https://docs.angularjs.org/api/ng/function/angular.copy for more details.
Upvotes: 2