Quantcast
Channel: Is there a pattern for dealing with "Cancel" in AngularJS modal dialogs? - Stack Overflow
Viewing all articles
Browse latest Browse all 7

Answer by Sharondio for Is there a pattern for dealing with "Cancel" in AngularJS modal dialogs?

$
0
0

You seem to be over-thinking this. There isn't a plug-in because the process is pretty simple. If you want a pristine copy of the model, make one and keep it in the controller. If a user cancels, reset the model to your copy and use the FormController.$setPristine() method to make the form pristine again.

//Controller:

myService.findOne({$route.current.params['id']}, function(results) {
    $scope.myModel = results;
    var backup = results;
}

//cancel
$scope.cancel = function() {
    $scope.myModel = backup;
    $scope.myForm.$setPristine();
}

Then in your view:

<form name="myForm">

You need to name the form to create the $scope.myForm controller.


Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>