javascript - Deleting a property from an object is removing the property from another object having similar names -
javascript - Deleting a property from an object is removing the property from another object having similar names -
i have 2 objects. 1 master data, similar object contains properties using , subset of master data. please find below 2 objects:
$scope.masterdata = { "storesfororgs": { "ppp0001188": ["007071","007073","007079"], "ppp0001189": ["007075","0070756","0070789"], "ppp0001190": ["007075","0070756","0070789", "00707893", "00707899"] } } $scope.masterdatafordisplay = { "storesfororgsdisplay": { } }
if in code
$scope.masterdatafordisplay = $scope.masterdata;
this linking both objects , if alter masterdatafordisplay changing masterdata well. understand comparing these 2 create same reference , avoided using
try
$scope.masterdatafordisplay = json.parse(json.stringify($scope.masterdata));
but when code not executed happening. objects beingness initialized before?
use this:
$scope.masterdatafordisplay = angular.copy($scope.masterdata);
instead of
$scope.masterdatafordisplay = $scope.masterdata;
copy() : creates deep re-create of source, should object or array. dont share same reference
javascript angularjs
Comments
Post a Comment