Code Monkey home page Code Monkey logo

Comments (14)

bushiko avatar bushiko commented on May 25, 2024 1

I needed to close an opened modal every time an ui router stateChange event fires. I ended up writing a decorator to keep track of opened modals promises:

  var decorator = function($delegate, $rootScope) {
    var ModalList = [];
    var originalShow = $delegate.showModal;
    $delegate.showModal = function(args) {
      // showModal retorna una promesa,
      // guardaré la lista de promesas para poderlas cerrar
      var promise = originalShow.apply(null, [args]);
      ModalList.push(promise);
      return promise;
    };
    $rootScope.$on('$stateChangeSuccess', function(event) {
      ModalList.forEach(function(modalPromise) {
        modalPromise.then(function(modal) {
          console.log('closing modal due to state change...');
          modal.element.modal('hide');
           // Remover de la lista
          var idx = ModalList.indexOf(modalPromise);
          ModalList.splice(idx, 1);
        })
      });
    });
    return $delegate
  }
  return decorator;

and added like this in my module config phase:

$provide.decorator('ModalService', decorator);

from angular-modal-service.

chris-hanson avatar chris-hanson commented on May 25, 2024

+1

from angular-modal-service.

elizabeth-young avatar elizabeth-young commented on May 25, 2024

+1

from angular-modal-service.

Artforge avatar Artforge commented on May 25, 2024

+1

from angular-modal-service.

mbarre avatar mbarre commented on May 25, 2024

+1

from angular-modal-service.

skolsuper avatar skolsuper commented on May 25, 2024

+1

from angular-modal-service.

klindberg avatar klindberg commented on May 25, 2024

+1

from angular-modal-service.

jdrorrer avatar jdrorrer commented on May 25, 2024

+1

from angular-modal-service.

imziyang avatar imziyang commented on May 25, 2024

+1

from angular-modal-service.

vinicius33 avatar vinicius33 commented on May 25, 2024

+1

from angular-modal-service.

paulashton avatar paulashton commented on May 25, 2024

+1

from angular-modal-service.

lorenzodianni avatar lorenzodianni commented on May 25, 2024

News?

from angular-modal-service.

dwmkerr avatar dwmkerr commented on May 25, 2024

Hi everyone, I'm starting on this now!

from angular-modal-service.

dwmkerr avatar dwmkerr commented on May 25, 2024

The easiest way (as of [0.12]9https://github.com/dwmkerr/angular-modal-service/releases/tag/v0.12.0) is to do this with a preClose hook:

ModalService.showModal({
  templateUrl: "some/bootstrap-template.html",
  controller: "SomeController",
  preClose: (modal) => { modal.element.modal('hide'); }
}).then(function(modal) {
  // etc
});

Apologies for the delays everyone, it's hard to find time to work on my open source projects when I'm super busy at work!

from angular-modal-service.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.