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?