samedi 6 décembre 2014

Angular values update in both elements


Vote count:

0




I am adding same element (json object) into a list (from another list) twice using .copy to break the reference. But even after doing that when I change some values in one both of them are getting updated.




$scope.addProduct = function (item) {
var index = $scope.itemsProduct.indexOf(item);
$scope.scopItem = {};
angular.copy(item , $scope.scopItem);
for(var j in $scope.scopItem['vVolume']) {
$scope.scopItem['ABC'][j].dataType='Discount';
$scope.scopItem['ABC'][j]['Discount'] = '';
}
if (index != -1) {
$scope.itemsTags.push($scope.scopItem);
$timeout(function() {
$scope.$apply(function () {
$scope.calculate($scope.scopItem);
});
}, 10);
}
};


Need help as even i am not adding the same element(using .copy) and updating the "Discount" property of one updates both?? Note: ABC is a inner list with property as "Discount" and I am changing "Discount"




asked 1 min ago







Angular values update in both elements

Aucun commentaire:

Enregistrer un commentaire