LoginSignup
2

More than 5 years have passed since last update.

UI BootstrapのModalが取り残されるのを回避する方法

Last updated at Posted at 2016-05-31

AngularJSとUI BootstrapでModalを表示するとブラウザの戻るボタンを押したり、ChromeだとBackspaceキーを押して前の画面に戻ったときに取り残されてしまう。

回避方法

sample.js
$rootScope.$on('$locationChangeStart', function() {
  if ($uibModalInstance.opened) {
    $uibModalInstance.dismiss('cancel');
  }
});

$locationChangeStartでURLの変更を検知して、閉じてあげる。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2