@@ -110,8 +110,7 @@ angular.module('ui.bootstrap.modal', [])
110110
111111 var OPENED_MODAL_CLASS = 'modal-open' ;
112112
113- var backdropjqLiteEl , backdropDomEl ;
114- var backdropScope = $rootScope . $new ( true ) ;
113+ var backdropDomEl , backdropScope ;
115114 var openedWindows = $$stackedMap . createNew ( ) ;
116115 var $modalStack = { } ;
117116
@@ -127,7 +126,9 @@ angular.module('ui.bootstrap.modal', [])
127126 }
128127
129128 $rootScope . $watch ( backdropIndex , function ( newBackdropIndex ) {
130- backdropScope . index = newBackdropIndex ;
129+ if ( backdropScope ) {
130+ backdropScope . index = newBackdropIndex ;
131+ }
131132 } ) ;
132133
133134 function removeModalWindow ( modalInstance ) {
@@ -146,6 +147,9 @@ angular.module('ui.bootstrap.modal', [])
146147 if ( backdropDomEl && backdropIndex ( ) == - 1 ) {
147148 backdropDomEl . remove ( ) ;
148149 backdropDomEl = undefined ;
150+
151+ backdropScope . $destroy ( ) ;
152+ backdropScope = undefined ;
149153 }
150154
151155 //destroy scope
@@ -174,12 +178,14 @@ angular.module('ui.bootstrap.modal', [])
174178 keyboard : modal . keyboard
175179 } ) ;
176180
177- var body = $document . find ( 'body' ) . eq ( 0 ) ;
181+ var body = $document . find ( 'body' ) . eq ( 0 ) ,
182+ currBackdropIndex = backdropIndex ( ) ;
178183
179- if ( backdropIndex ( ) >= 0 && ! backdropDomEl ) {
180- backdropjqLiteEl = angular . element ( '<div modal-backdrop></div>' ) ;
181- backdropDomEl = $compile ( backdropjqLiteEl ) ( backdropScope ) ;
182- body . append ( backdropDomEl ) ;
184+ if ( currBackdropIndex >= 0 && ! backdropDomEl ) {
185+ backdropScope = $rootScope . $new ( true ) ;
186+ backdropScope . index = currBackdropIndex ;
187+ backdropDomEl = $compile ( '<div modal-backdrop></div>' ) ( backdropScope ) ;
188+ body . append ( backdropDomEl ) ;
183189 }
184190
185191 var angularDomEl = angular . element ( '<div modal-window></div>' ) ;
0 commit comments