1

Keep default $scope data even when scope data changes.

  $scope.data={"a":"hello world"};

    $scope.data.a="changed data";

now become

$scope.data={"a":"changed data"};

how can i get old $scope data.ie, i need -

$scope.data={"a":"hello world"};

2 Answers 2

1

You can try this way with angular.copy You can write reset function. This way

  $scope.data={"a":"hello world"};
  var originalData = angular.copy($scope.data);

  $scope.data.a="changed data";

  $scope.reset = function() {
     angular.copy(originalData, $scope.data); 
  };
Sign up to request clarification or add additional context in comments.

Comments

1

Instead of directly assigning it to $scope.data, do a copy of it like below :

$scope.data2= angular.copy($scope.data);

$scope.data2.a = "changed data";

angular.copy creates a deep copy of the source object which is $scope.data here.

1 Comment

No problem . Glad I could help :). Please accept the answer if it helped, so that we can work on other questions :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.