有没有办法在路由更改时自动关闭 Angular UI Bootstrap 模式?

编程入门 行业动态 更新时间:2024-10-28 20:18:28
本文介绍了有没有办法在路由更改时自动关闭 Angular UI Bootstrap 模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我在模态内的模板中有链接.当我单击它们时,当前页面会发生变化,但叠加层和模态会保持不变.我可以将 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-21 06:44:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/997556.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:没有办法   路由   自动关闭   模式   Angular

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!