In my datagrid, I am displaying data from an array called listOfAttributes. Each row has an edit icon which, when clicked, reveals two buttons: save and cancel edit. The issue I am facing is that when a user clicks on cancel edit, the updated data should be cleared and the previously existing data should persist. I have tried using the splice method to add the previous object and delete the current one at the same time, but it does not seem to work as expected.
$scope.edit = function(attribute) {
angular.copy(attribute, $scope.copyAttr);
}
$scope.save = function(attribute){
// works fine;
}
$scope.cancelEdit = function(attribute) { // doesn't work
var indx = $scope.listOfAttributes.indexOf(attribute);
$scope.listOfAttributes.splice(indx, 0, $scope.copyAttr);
$scope.listOfAttributes.splice(indx,1);
}