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; }; }
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With