dwmkerr / angular-modal-service

Modal service for AngularJS - supports creating popups and modals via a service.
MIT License
626 stars 321 forks source link

Close callback being called multiple times when location changes #258

Closed DougKeller closed 5 years ago

DougKeller commented 5 years ago

TL;DR: If the location changes while waiting on an async operation before closing a modal, the cleanUpClose function is invoked multiple times, resulting in an exception:

TypeError: Cannot read property 'resolve' of null (line 206 of angular-modal-service.js)

Steps to Reproduce

  1. perform an async operation within a modal's controller, closing the modal once it's complete
    // ModalController
    $http.post('something').then(() => {
    close();
    });
  2. While the request is running, go to a different url
    $location.path('/some-other-url');
    • $locationChangeSuccess is broadcasted, which closes the modal
  3. async operation finishes
    • $http.post promise is resolved, causing close to be called
    • Because cleanUpClose was called already and set everything to null, the above exception is raised