0

Code for modal closing (from SO):

$rootScope.$on('$locationChangeStart', x => $uibModalStack.dismissAll("location change dismiss all"));

This listener is simply created once on app run and it properly closes all modals when location is changed. However, my problem is that it does it AFTER a controller is loaded from the new route, which is creating a modal:

app.controller(..., function(...){
...
dialog.create(template, 'DocumentSearchDialogController', {groups: documentGroups, callback: callback}, 'lg')

(where dialog is a simple wrapper for $uibModal)
So the modal is created and then instantly closed by the listener. I don't want that - I want the listener to clear modals before the controller creates the modal.
I've found one work-around: wrapping the modal creation in $timeout(..., 0) delays it to the next digest/apply, which happens after both controller and listener executed all their code. This isn't ideal - I'd like to simply clear modals before initializing controllers and, ideally, not touch any controller at all.
Edit: I am using UI-Router.

Scar
  • 148
  • 9

1 Answers1

0

It turns out, the listener I used is suboptimal when UI-Router is in use. In fact, I cannot even prevent the state change in my listener.
Instead, when using UI-Router, $transitions.onStart() should be used for listening to state changes.

Scar
  • 148
  • 9