Issue
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;
};
}
Solution
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);
};
}
Answered By - madhead
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.