Closed karan-kang closed 5 years ago
Are these life cycle hooks part of Angular 1.5? Or does it exist in 1.4 too?
These life cycle hooks are part of Angular 1.5. You can read more about them here: https://docs.angularjs.org/api/ng/service/$compile#life-cycle-hooks or https://blog.thoughtram.io/angularjs/2016/03/29/exploring-angular-1.5-lifecycle-hooks.html
For now, I am using this a workaround. This only works if the modal controller is using the controllerAs syntax:
$modal({
...,
onBeforeShow: function($modal) {
// Angular 1.5 $onInit and $onDestroy life cycle event support
if ($modal.$options.controllerAs) {
var modalPromise = $modal.$promise;
if (modalPromise) {
modalPromise.then(function(val) {
if (val && val.locals) {
var modalScope = val.locals.$scope;
if (modalScope) {
var controller = modalScope[$modal.$options.controllerAs];
if (controller) {
// Manually trigger $onInit callback
if (angular.isFunction(controller.$onInit)) {
controller.$onInit();
}
// Manually trigger $onDestroy callback on scope destroy
if (angular.isFunction(controller.$onDestroy)) {
modalScope.$on('$destroy', controller.$onDestroy);
}
}
}
}
});
}
}
}
})
This workaround should work with $compileProvider.debugInfoEnabled(false);
Are you able to figure out where the changes could be natively for Angular-Strap?
If so, a PR would be welcome 👍
You can decorate the $modal service generally not just the actual instance (based on @Karankang007's solution)
https://gist.github.com/cstuncsik/4b6da0b2df0e02e1c842c28ddace344a
Is there an example of how to call the $modal with a component?
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.
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.
Modal dialog controllers currently do not trigger $onInit and $onDestroy life cycles hooks.