My AngularJs application has the functionality to detect a change in state (using ui.router) and prompt the user to save any unsaved changes. Currently, I am utilizing a confirm dialog for this task:
$scope.$on('$stateChangeStart', () => {
if (self.changed && confirm('There are unsaved changes. Do you want to save them?'))
this.save();
});
I have been looking into switching to using the $modal
dialog from the bootstrap UI library. However, I encountered an issue where the $modal.open()
call is asynchronous and returns immediately, causing the state to change before the dialog can open.
$scope.$on('$stateChangeStart', () => {
if (self.changed)
this.$dialog.open({...}).result.then(()=>{
this.save();
});
});
I am wondering if there is a solution to prevent this problem or if I should stick with the plain JavaScript confirm dialog?