有没有办法在路由更改时自动关闭 Angular UI Bootstrap 模式? [英] Is there a way to automatically close Angular UI Bootstrap modal when route changes?

查看:29
本文介绍了有没有办法在路由更改时自动关闭 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 :-)

这篇关于有没有办法在路由更改时自动关闭 Angular UI Bootstrap 模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆