1
I have a grid with the data and also has an edit button.
Problem: When I click on change and start modifying the data, there on the grid the data is being changed too, even without having saved.
My function that loads the data is this:
/* Função que carrega na grid, TODOS os pacientes cadastrados */
$scope.loadPacientes = function(){
OdontoService.load('rest/paciente/loadPacientes').then(function (data) {
$scope.pacientes = data.data;
/* For para formatar a data no formato certo */
for(var x = 0; x < $scope.pacientes.length; x++){
$scope.pacientes[x].dataNascimento = new Date($scope.pacientes[x].dataNascimento);
}
},function (error){
console.log(error);
});
}
I wanted the data to be changed only on the grid, when I saved and not when I am editing yet.
This is probably because the data in the grid is associated with the same "model" in both the editing and grid, what you can do is use an auxiliary model only for editing and assign the value only when confirming the editing.
– BrTkCa
@Lucascosta and it is good practice to do this?
– Guilherme Nass
yes @Guilhermenass, if you want this behavior I see no other alternative, because if a scope variable is being used in n places, when it is changed all the places that are displaying it will be changed as well, blame the Binding :p date
– BrTkCa
@Lucascosta Got it man, hehe. Thanks a lot for the help! .
– Guilherme Nass