Saturday, May 25, 2024
 Popular · Latest · Hot · Upcoming
195
rated 0 times [  200] [ 5]  / answers: 1 / hits: 48263  / 11 Years ago, tue, july 9, 2013, 12:00:00

I've created a fiddle here: http://jsfiddle.net/nicktest2222/W4VaA/



I just want to be able to hit the reset button and put my original values back. Does anyone know the best way to go about doing this?



Thanks in advance



function TodoCtrl($scope) {
$scope.data = [
{text:'learn angular', done:true},
{text:'build an angular app', done:false}];

$scope.orig = [$scope.data];

$scope.reset = function() {
$scope.data = $scope.orig;
};

}

More From » angularjs

 Answers
44

The problem is in JS clone mechanics. All you need to do is to create a deep copy of your model:



function TodoCtrl($scope) {
$scope.data = [
{text:'learn angular', done:true},
{text:'build an angular app', done:false}
];

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

$scope.reset = function() {
$scope.data = angular.copy($scope.orig);
};
}


Here is the updated fiddle.


[#77104] Monday, July 8, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aileent

Total Points: 556
Total Questions: 107
Total Answers: 101

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
;