is shown to the user asking Changes you made may not be saved. Leave anyway?.You can change the message with
dirtyCheckServiceProvider.setDirtyMessage()js
module.config(config);config.$inject = ['dirtyCheckServiceProvider'];
function config(dirtyCheckServiceProvider) {
dirtyCheckServiceProvider.setDirtyMessage('Wanna leave?');
}
`or change the entire dialog being shown providing your own
dirtyCheckDialog function returning a thenable object. If the promise is fulfilled the navigation is executed, otherwise it's not and the user stays where he is.Example using [ngDialog][4] (
openConfirm()js
var module = angular.module('yourApp', [
'angularDirtyCheck',
'ngDialog'
]);module.service('dirtyCheckDialog', dirtyCheckDialog);
dirtyCheckDialog.$inject = ['ngDialog'];
function dirtyCheckDialog(ngDialog) {
return {
show: function () {
return ngDialog.openConfirm({
template: 'dialog.tpl.html'
});
}
};
}
`
[4]: https://github.com/likeastore/ngDialogor [$mdDialog][5] from Angular Material (
$mdDialog.show()js
var module = angular.module('yourApp', [
'angularDirtyCheck',
'ngMaterial'
]);module.service('dirtyCheckDialog', dirtyCheckDialog);
dirtyCheckDialog.$inject = ['$mdDialog'];
function dirtyCheckDialog($mdDialog) {
return {
show: function () {
return $mdDialog.show({
templateUrl: 'dialog.tpl.html',
controller: ['$scope', '$mdDialog', function($scope, $mdDialog) {
$scope.stay = function () {
$mdDialog.cancel();
};
$scope.leave = function () {
$mdDialog.hide();
};
}]
});
}
};
}
`[5]: https://material.angularjs.org/latest/api/service/$mdDialog
Build it
Get a clone and run
`The built file is located under
./dist.To run the demo locally run
`and navigate your browser to
http://localhost:8080/dev_index.html`. Source changes will trigger a refresh.