user3626386 user3626386 - 2 months ago 7x
AngularJS Question

Angular changes values in all arrays

my code is here:
i think problem is here:

angular.copy($scope.items[$index], $scope.editedItem);

but i define which array is to be changed

please add 2 time pizza margharitta.
In the right column is json of array $scope.items
so, when im adding 2 times the same item, and trying to change price one of it(and then click green button) angular is changing price in all arrays.
I found something similar

So, what am I doing wrong, and why angular is changing value price ('cena') in all arrays

Sorry for my english


Adjust the body of your $scope.dodajPozycjeDoParagonu() function like this:

  $scope.dodajPozycjeDoParagonu = function(index, index2) {
    var item = {};
    angular.copy($scope.produkty[index].produkty[index2], item);
    $scope.items.push(item); ...

This should do the trick. Hope it helps.