I'm trying to fire events for all UI modals that I have across the project, I want an event to fire when any UI modal opens or closes ?
Example:
anymodal.opened.then(function() {});
I'm trying to fire events for all UI modals that I have across the project, I want an event to fire when any UI modal opens or closes ?
Example:
anymodal.opened.then(function() {});
Taken from the docs (version 2.1.4)
The open method returns a modal instance, an object with the following properties:
close(result) (Type: function) - Can be used to close a modal, passing a result.
dismiss(reason) (Type: function) - Can be used to dismiss a modal, passing a reason.
result (Type: promise) - Is resolved when a modal is closed and rejected when a modal is dismissed.
opened (Type: promise) - Is resolved when a modal gets opened after downloading content's template and resolving all variables.
closed (Type: promise) - Is resolved when a modal is closed and the animation completes.
rendered (Type: promise) - Is resolved when a modal is rendered.
What you are looking for is the last three.
Use them as you would normally with a modal instance
var modalInstance = $uibModal.open({
// define you modal here ...
});
modalInstance.result.then(function(selectedItem) {
$ctrl.selected = selectedItem;
}, function() {
$log.info('Modal dismissed at: ' + new Date());
});
modalInstance.opened.then(function() {
console.log("modal opened");
})
modalInstance.closed.then(function() {
console.log("modal closed");
})
modalInstance.rendered.then(function() {
console.log("modal rendered");
})