Since objects are passed by reference, you need to create a new object to store the default configuration. Otherwise, if you change $scope.last_good_configuration it also affects $scope.storage , since both of them point to the same object.
Use the angular.extend method, which will copy all the properties from $scope.storage into the new object {} :
$scope.last_good_configuration = angular.extend({}, $scope.storage);
UPD I completely forgot about highlighted angular.copy , which is probably more appropriate in this case, especially $scope.storage has a nested object structure: angualar.extend will make a shallow copy, in this case you should use angular.copy (see answer Satpal).
source share