Problem editing data - AngularJS

1

I have a grid with the data and also has an edit button.

Problem: When I click on change and start to modify the data, there on the grid the data is being changed too, even without saving.

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 only change on the grid, when I saved it and not when I'm still editing.

    
asked by anonymous 06.06.2017 / 00:35

1 answer

0

If the scope variable is being used in more than one place, if modified, it will show the change where it is being applied to view , this is due to data binding that automatically synchronizes the data between the model and the view .

To prevent this situation in your scenario, you can create a helper scope variable and associate editing.

    
06.06.2017 / 21:45