@@ -110,8 +110,7 @@ angular.module('ui.bootstrap.modal', [])
110
110
111
111
var OPENED_MODAL_CLASS = 'modal-open' ;
112
112
113
- var backdropjqLiteEl , backdropDomEl ;
114
- var backdropScope = $rootScope . $new ( true ) ;
113
+ var backdropDomEl , backdropScope ;
115
114
var openedWindows = $$stackedMap . createNew ( ) ;
116
115
var $modalStack = { } ;
117
116
@@ -127,7 +126,9 @@ angular.module('ui.bootstrap.modal', [])
127
126
}
128
127
129
128
$rootScope . $watch ( backdropIndex , function ( newBackdropIndex ) {
130
- backdropScope . index = newBackdropIndex ;
129
+ if ( backdropScope ) {
130
+ backdropScope . index = newBackdropIndex ;
131
+ }
131
132
} ) ;
132
133
133
134
function removeModalWindow ( modalInstance ) {
@@ -146,6 +147,9 @@ angular.module('ui.bootstrap.modal', [])
146
147
if ( backdropDomEl && backdropIndex ( ) == - 1 ) {
147
148
backdropDomEl . remove ( ) ;
148
149
backdropDomEl = undefined ;
150
+
151
+ backdropScope . $destroy ( ) ;
152
+ backdropScope = undefined ;
149
153
}
150
154
151
155
//destroy scope
@@ -174,12 +178,14 @@ angular.module('ui.bootstrap.modal', [])
174
178
keyboard : modal . keyboard
175
179
} ) ;
176
180
177
- var body = $document . find ( 'body' ) . eq ( 0 ) ;
181
+ var body = $document . find ( 'body' ) . eq ( 0 ) ,
182
+ currBackdropIndex = backdropIndex ( ) ;
178
183
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 ) ;
183
189
}
184
190
185
191
var angularDomEl = angular . element ( '<div modal-window></div>' ) ;
0 commit comments