Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- angular.module('app', ['mgcrea.ngStrap']).config(['$provide', $provide => {
- $provide.decorator('$modal', $delegate => config => {
- const createConfigMethodDecorator = (orignalMethod, lifeCycleEventName) => $m => {
- if (config.controllerAs) {
- const modalPromise = $m.$promise
- if (modalPromise) {
- modalPromise.then(val => {
- if (val && val.locals) {
- const modalScope = val.locals.$scope
- if (modalScope) {
- const ctrl = modalScope[config.controllerAs]
- if (ctrl) {
- if (angular.isFunction(ctrl[lifeCycleEventName])) {
- ctrl[lifeCycleEventName]()
- }
- }
- }
- }
- })
- }
- }
- if (angular.isFunction(orignalMethod)) {
- orignalMethod($m)
- }
- }
- config.onBeforeShow = createConfigMethodDecorator(config.onBeforeShow, '$onInit')
- config.onBeforeHide = createConfigMethodDecorator(config.onBeforeHide, '$onDestroy')
- return $delegate(config)
- })
- }])
Add Comment
Please, Sign In to add comment