mgcrea / angular-strap

AngularJS 1.2+ native directives for Bootstrap 3.
mgcrea.github.io/angular-strap
MIT License
5.73k stars 1.38k forks source link

Modal - does not remove classes from `body` when calling `destroy` #2144

Closed michaelvashchinsky closed 5 years ago

michaelvashchinsky commented 8 years ago

The modal does not remove classes modal-open modal-with-am-fade (or similar) from body when calling destroy().

If you have your modal opened and click back browser's button to navigate to another route - the modal just stays open. So I have a service that listens to $scope.$destroy and calls remove() on each opened modal.

remove() has removal of backdropElement, but not for CSS classes on body.

I tried to call hide() on the modal instance and it has async call to leaveAnimateCallback in hide(), but it is not fired (due to scope being destoryed?).

Thank you.

pablotarga commented 8 years ago

I was able to solve this by calling the leaveAnimateCallback inside the destroyModalElement

  function destroyModalElement() {
    if ($modal.$isShown && modalElement !== null) {
      unbindBackdropEvents();
      unbindKeyboardEvents();
    }

    leaveAnimateCallback()

    if (modalScope) {
      modalScope.$destroy();
      modalScope = null;
    }
    if (modalElement) {
      modalElement.remove();
      modalElement = $modal.$element = null;
    }
  }
stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.