material icon indicating copy to clipboard operation
material copied to clipboard

dialog: close dialog on location change

Open cpae opened this issue 11 years ago • 5 comments

You should consider closing dialogs when the location changes (e.g. $location.path(...) or browser back-button). Otherwise weird stuff starts to happen as the underlying controller is gone.

I fixed that in my base controller using: $rootScope.$on('$routeChangeStart', function() { $mdDialog.cancel(); })

A possible fix has already been implemented for angular-ui, so you might want to apply that for angular material:

https://github.com/angular-ui/bootstrap/commit/474ce52e8eadee763987ebd930cf790d4bcd6d97

cpae avatar Jun 23 '15 13:06 cpae

@ThomasBurleson What do you think about implementing this into the logic for MdPanels instead of adding more logic into MdDialog? @ErinCoughlan and I are working on functionality for multiple MdPanels that would allow for methods to be run on more than one MdPanel that would solve this issue.

bradrich avatar Jul 29 '16 13:07 bradrich

@bradrich If it were added to MdPanel, it would be another configuration option. I'm not against it, but it can't happen with every panel as opposed to dialogs where it's possible to do always.

@ThomasBurleson Something to consider with this FR is to also add a callback onClose so that when the user tries to navigate back and there are unsaved edits, the user can be alerted and the close/navigation event can be cancelled. This is definitely needed for MdPanel.

ErinCoughlan avatar Jul 29 '16 17:07 ErinCoughlan

I agree with @bradrich that we need to move all possible components to mdPanel and implement this fix there only, because the same issue exists in mdPanel for now.

ivan-zakharchuk avatar Aug 24 '16 22:08 ivan-zakharchuk

$rootScope.$on('$routeChangeStart', function() { $mdDialog.cancel(); })

This will cause weird bugs if you have dialog states, states which open a dialog on their entrance event.

alirezamirian avatar Sep 10 '16 11:09 alirezamirian

ngDialog has implemented this: https://github.com/likeastore/ngDialog#closebynavigation-boolean Maybe useful for reference.

dbrgn avatar Dec 19 '16 11:12 dbrgn