有没有办法在路由更改时自动关闭 Angular UI Bootstrap 模式?
我在模态内的模板中有链接.当我单击它们时,当前页面会发生变化,但叠加层和模态会保持不变.我可以将 ng-click="dimiss()"
添加到模式中所有模板中的每个链接,但是有更好的方法吗?例如.在成功更改路线时自动关闭它,还是为每个模板添加一个 ng-click
来处理所有链接?
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?
如果您希望在成功更改路线时关闭所有打开的模式,您可以在一个中心位置通过收听 $routeChangeSuccess
事件,例如在您的应用程序的运行块中:
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:
var myApp = angular.module('app', []).run(function($rootScope, $uibModalStack) {
$uibModalStack.dismissAll();
});
在这里您可以看到 $uibModalStack
服务被注入,您可以在该服务上调用 dismissAll
方法 - 此调用将关闭所有当前打开的模态.
Here you can see that the $uibModalStack
service gets injected on which you can call the dismissAll
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 :-)