在 URL 更改时关闭角度模式 - 控制台中的错误 [英] Dismiss angular modal on URL change - errors in console

查看:21
本文介绍了在 URL 更改时关闭角度模式 - 控制台中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Angular bootstrap Modal 来显示一个弹出窗口.单击文本区域/浏览器后退按钮外的退格键时,我想取消弹出窗口并继续更改 url.默认行为是模态后面的页面发生变化,但模态保持在顶部.

I'm using Angular bootstrap Modal to show a popup window. On clicking backspace outside the textarea / browser back button, i want to cancel the popup and continue with the url change. The default behaviour is that page behind the modal changes, but the modal remains on top.

在模态实例的控制器中,我添加了一个

In the controller for the modal instance, I added a

$scope.$on('$routeChangeStart', function() {...} );

$scope.$on('$routeChangeStart', function() {...} );

它可以工作,但是每当再次调用控制器时我都会看到错误.$modalInstance.dismiss() 再次被调用,但在库内部,它抛出异常.

It works, but I'm seeing errors whenever the controller is invoked again. The $modalInstance.dismiss() is called again, but inside the library, it throws an exception.

这是带有代码和重现步骤的 plunkr.观察浏览器控制台是否有错误.

Here's the plunkr with code and repro steps. Watch the browser console for the error.

http://plnkr.co/UKXa6uFvy0ODHylMj28s

我做错了什么,还是 modal.js 中的错误?

Am I doing something wrong, or is it a bug in modal.js?

我认为我的控制器范围不正确.为什么在导航到 MainCtrl 时会调用 AddCtrl 的 $scope.$on('$routeChangeStart'?

I don't think my controller scope is right. Why would AddCtrl's $scope.$on('$routeChangeStart' be called when I navigate to MainCtrl?

推荐答案

你的 plunker 似乎是对的.

Your plunker seems to be right.

这里存在 $modal 服务错误:关闭模态窗口后,模态范围仍然存在.所以模态范围继续监听 $routeChangeStart 并且我认为 dismiss() 的双重调用会导致错误.

There is $modal service bug here: the modal scope is still alive after you close a modal window. So modal scope continue to listen $routeChangeStart and I consider that double call of dismiss() cause an error.

此问题将在下一个 UI Bootstrap 版本中解决.

This issue will be solved in next UI Bootstrap release.

我更新并评论了您的代码,希望对您有所帮助 - http://plnkr.co/edit/daf8dP?p=info

I update and comment your code, hope this help - http://plnkr.co/edit/daf8dP?p=info

这篇关于在 URL 更改时关闭角度模式 - 控制台中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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