When user entered some data in form and tried to close browser window accidentally, system has to show alert message to save their data. This example is to implement this functionality using AngularJS. Observe below two functions
<input ng-change="setConfirmUnload(true)" ng-model="data"/> <button ng-click="saveData()">Save Data</button> <div ng-bind="data1"></div>
$scope.setConfirmUnload = function(on) { window.onbeforeunload = (on) ? $scope.unloadMessage : null; } $scope.unloadMessage = function() { return "You have unsaved changes"; } $scope.saveData = function() { $scope.data1 = $scope.data; $scope.setConfirmUnload(false); }
0 comments:
Post a Comment