Dismiss angular modal on URL change - errors in console

痞子三分冷 提交于 2019-12-06 13:23:14

问题


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() {...} );

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.

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

http://plnkr.co/UKXa6uFvy0ODHylMj28s

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

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


回答1:


Your plunker seems to be right.

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.

This issue will be solved in next UI Bootstrap release.

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




回答2:


I have a comprehensive solution on dismissing Angular modal when route change / back button clicking here.



来源:https://stackoverflow.com/questions/22286457/dismiss-angular-modal-on-url-change-errors-in-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!