Comments (14)
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.
+1
from angular-modal-service.
+1
from angular-modal-service.
+1
from angular-modal-service.
+1
from angular-modal-service.
+1
from angular-modal-service.
+1
from angular-modal-service.
+1
from angular-modal-service.
+1
from angular-modal-service.
+1
from angular-modal-service.
+1
from angular-modal-service.
News?
from angular-modal-service.
Hi everyone, I'm starting on this now!
from angular-modal-service.
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)
- ModalService.closeModals() - Dont close other modals HOT 2
- modal dismiss HOT 4
- Memory leak HOT 2
- modal is not showing up but code js is ok
- Modal not getting closed HOT 3
- Modal service not working with bootstrap 4 beta (popper.js issue)
- Request: Upgrade to Angular 2 (and higher) HOT 2
- Browser support for angular-modal-service HOT 2
- doing operations on modal close HOT 1
- An in-range update of karma is breaking the build 🚨 HOT 15
- Close callback being called multiple times when location changes
- null is not an object (evaluating 'r.resolve')
- request: make it compatible with AngularJS 1.7 HOT 1
- Jquery datepicker not open issue in modal HOT 1
- An in-range update of webpack is breaking the build 🚨 HOT 21
- Latest version capture any angular error through the modal service
- Component bindings are bound too late HOT 3
- Can't overlay modals HOT 1
- An in-range update of uglify-js is breaking the build 🚨 HOT 22
- Close in a single controller?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-modal-service.