Guest User

Untitled

a guest
Nov 22nd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. angular.module('app', ['mgcrea.ngStrap']).config(['$provide', $provide => {
  2.  
  3. $provide.decorator('$modal', $delegate => config => {
  4.  
  5. const createConfigMethodDecorator = (orignalMethod, lifeCycleEventName) => $m => {
  6. if (config.controllerAs) {
  7. const modalPromise = $m.$promise
  8. if (modalPromise) {
  9. modalPromise.then(val => {
  10. if (val && val.locals) {
  11. const modalScope = val.locals.$scope
  12. if (modalScope) {
  13. const ctrl = modalScope[config.controllerAs]
  14. if (ctrl) {
  15. if (angular.isFunction(ctrl[lifeCycleEventName])) {
  16. ctrl[lifeCycleEventName]()
  17. }
  18. }
  19. }
  20. }
  21. })
  22. }
  23. }
  24.  
  25. if (angular.isFunction(orignalMethod)) {
  26. orignalMethod($m)
  27. }
  28. }
  29.  
  30. config.onBeforeShow = createConfigMethodDecorator(config.onBeforeShow, '$onInit')
  31. config.onBeforeHide = createConfigMethodDecorator(config.onBeforeHide, '$onDestroy')
  32.  
  33. return $delegate(config)
  34. })
  35. }])
Add Comment
Please, Sign In to add comment