Edit array inside another array

2

I'm new to AngularJS and I have the following situation:

I have a list of categories and within this list of categories there is a product listing for that category.

Example: Smartphones > Galaxy, iPhone, etc ...

The problem is that I can not save the edition I make of this array of products that are within the array of categories.

I've created a Codepen to better illustrate this.

I understand that $scope.save is saving the table, not the content, but I have no idea how to save the contents instead of the table.

I would really appreciate your help, thank you in advance.

    
asked by anonymous 07.02.2018 / 23:42

1 answer

1

I create a fork of your codepen with a possible solution.

Basically - save a reference to the original object:

$scope.edit = function(user, i) {
    $scope.source = user; // Preservando a referência
    $scope.update = angular.copy(user);
};

And use angular.merge() to overwrite the properties of the original object with those of the modified clone :

$scope.save = function() {
    angular.merge($scope.source, $scope.update); // Atualiza o objeto referenciado
    $scope.update = ""; // reseta o update
};
    
08.02.2018 / 00:09