@@ -2498,26 +2498,28 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2498
2498
var fragment = document . createDocumentFragment ( ) ;
2499
2499
fragment . appendChild ( firstElementToRemove ) ;
2500
2500
2501
- // Copy over user data (that includes Angular's $scope etc.). Don't copy private
2502
- // data here because there's no public interface in jQuery to do that and copying over
2503
- // event listeners (which is the main use of private data) wouldn't work anyway.
2504
- jqLite ( newNode ) . data ( jqLite ( firstElementToRemove ) . data ( ) ) ;
2505
-
2506
- // Remove data of the replaced element. We cannot just call .remove()
2507
- // on the element it since that would deallocate scope that is needed
2508
- // for the new node. Instead, remove the data "manually".
2509
- if ( ! jQuery ) {
2510
- delete jqLite . cache [ firstElementToRemove [ jqLite . expando ] ] ;
2511
- } else {
2512
- // jQuery 2.x doesn't expose the data storage. Use jQuery.cleanData to clean up after
2513
- // the replaced element. The cleanData version monkey-patched by Angular would cause
2514
- // the scope to be trashed and we do need the very same scope to work with the new
2515
- // element. However, we cannot just cache the non-patched version and use it here as
2516
- // that would break if another library patches the method after Angular does (one
2517
- // example is jQuery UI). Instead, set a flag indicating scope destroying should be
2518
- // skipped this one time.
2519
- skipDestroyOnNextJQueryCleanData = true ;
2520
- jQuery . cleanData ( [ firstElementToRemove ] ) ;
2501
+ if ( jqLite . hasData ( firstElementToRemove ) ) {
2502
+ // Copy over user data (that includes Angular's $scope etc.). Don't copy private
2503
+ // data here because there's no public interface in jQuery to do that and copying over
2504
+ // event listeners (which is the main use of private data) wouldn't work anyway.
2505
+ jqLite ( newNode ) . data ( jqLite ( firstElementToRemove ) . data ( ) ) ;
2506
+
2507
+ // Remove data of the replaced element. We cannot just call .remove()
2508
+ // on the element it since that would deallocate scope that is needed
2509
+ // for the new node. Instead, remove the data "manually".
2510
+ if ( ! jQuery ) {
2511
+ delete jqLite . cache [ firstElementToRemove [ jqLite . expando ] ] ;
2512
+ } else {
2513
+ // jQuery 2.x doesn't expose the data storage. Use jQuery.cleanData to clean up after
2514
+ // the replaced element. The cleanData version monkey-patched by Angular would cause
2515
+ // the scope to be trashed and we do need the very same scope to work with the new
2516
+ // element. However, we cannot just cache the non-patched version and use it here as
2517
+ // that would break if another library patches the method after Angular does (one
2518
+ // example is jQuery UI). Instead, set a flag indicating scope destroying should be
2519
+ // skipped this one time.
2520
+ skipDestroyOnNextJQueryCleanData = true ;
2521
+ jQuery . cleanData ( [ firstElementToRemove ] ) ;
2522
+ }
2521
2523
}
2522
2524
2523
2525
for ( var k = 1 , kk = elementsToRemove . length ; k < kk ; k ++ ) {
0 commit comments