I've got links in templates inside modals. When I click them, the current page changes, but the overlay and modal stay. I could add ng-click="dimiss()"
to every link in all templates in modals, but is there a better way? E.g. to close it automatically on successful route change or add just one ng-click
per template to handle all links?
相关问题
- angularJS: ui-router equivalent to $location.searc
- Separate AngularJS Controllers Into Separate Files
- Angular ngAnimate not working first time on page l
- Ionic Spinner not showing up
- Upload file to Google Cloud Storage using AngularJ
相关文章
- Passing variable through URL with angular js
- Watch entire object (deep watch) with AngularJS
- Angular ng-if change span text
- Can ng-show directive be used with a delay
- AngularJS $routeParams vs $stateParams
- Multiple parameters in AngularJS $resource GET
- How to set class/style of accordion heading in Ang
- PUT to S3 with presigned url gives 403 error
I resolved this issue by doing something like this:
A better way is to see that whenever a Popup (Modal) is open, on Browser Back button click (or Keyboard Back), we stop the URL change and just close the Popup. This works for a better User Experience in my Project.
The Browser Back button works normally if there is no Modal opened.
use:
or
Sample code:
I am keeping this logic in the modal controller. You can listen to
$locationChangeStart
event and close modal there. It is also good to remove listener after, especially if you have registered a listener on$rootScope
:If you want all the opened modals to be closed whenever a route is changed successfully, you could do it in one central place by listening to the
$routeChangeSuccess
event, for example in a run block of your app:Here you can see that the
$uibModalStack
service gets injected on which you can call thedismissAll
method - this call will close all the currently opened modals.So, yes, you can handle modals closing centrally, in one place, with one line of code :-)
check for the respective route condition in the event
$stateChangeSuccess
and then close the open bootstrap modals globally using the class like this:If you want to hide any other modals such as angular material dialog (
$mdDialog
) & sweet alert dialog's useangular.element('.modal-dialog').hide();
&angular.element('.sweet-alert').hide();
I don't actually use Angular UI Bootstrap, but from looking at the docs, it looks like there is a
close()
method on the$modalInstance
object.So taking the example from the docs, this should work:
Hope that helps.