@@ -1437,11 +1437,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1437
1437
if ( nodeLinkFn . scope ) {
1438
1438
childScope = scope . $new ( ) ;
1439
1439
compile . $$addScopeInfo ( jqLite ( node ) , childScope ) ;
1440
- var destroyBindings = nodeLinkFn . $$destroyBindings ;
1441
- if ( destroyBindings ) {
1442
- nodeLinkFn . $$destroyBindings = null ;
1443
- childScope . $on ( '$destroyed' , destroyBindings ) ;
1444
- }
1445
1440
} else {
1446
1441
childScope = scope ;
1447
1442
}
@@ -1460,8 +1455,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1460
1455
childBoundTranscludeFn = null ;
1461
1456
}
1462
1457
1463
- nodeLinkFn ( childLinkFn , childScope , node , $rootElement , childBoundTranscludeFn ,
1464
- nodeLinkFn ) ;
1458
+ nodeLinkFn ( childLinkFn , childScope , node , $rootElement , childBoundTranscludeFn ) ;
1465
1459
1466
1460
} else if ( childLinkFn ) {
1467
1461
childLinkFn ( scope , node . childNodes , undefined , parentBoundTranscludeFn ) ;
@@ -2025,8 +2019,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2025
2019
return elementControllers ;
2026
2020
}
2027
2021
2028
- function nodeLinkFn ( childLinkFn , scope , linkNode , $rootElement , boundTranscludeFn ,
2029
- thisLinkFn ) {
2022
+ function nodeLinkFn ( childLinkFn , scope , linkNode , $rootElement , boundTranscludeFn ) {
2030
2023
var i , ii , linkFn , controller , isolateScope , elementControllers , transcludeFn , $element ,
2031
2024
attrs ;
2032
2025
@@ -2060,24 +2053,28 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2060
2053
compile . $$addScopeClass ( $element , true ) ;
2061
2054
isolateScope . $$isolateBindings =
2062
2055
newIsolateScopeDirective . $$isolateBindings ;
2063
- initializeDirectiveBindings ( scope , attrs , isolateScope ,
2064
- isolateScope . $$isolateBindings ,
2065
- newIsolateScopeDirective , isolateScope ) ;
2056
+ var parentWatchDestroyer = initializeDirectiveBindings ( scope , attrs , isolateScope ,
2057
+ isolateScope . $$isolateBindings ,
2058
+ newIsolateScopeDirective ) ;
2059
+ if ( parentWatchDestroyer ) {
2060
+ isolateScope . $on ( '$destroy' , parentWatchDestroyer ) ;
2061
+ }
2066
2062
}
2067
2063
if ( elementControllers ) {
2068
2064
// Initialize bindToController bindings for new/isolate scopes
2069
2065
var scopeDirective = newIsolateScopeDirective || newScopeDirective ;
2070
2066
var bindings ;
2071
2067
var controllerForBindings ;
2068
+ var destroyBindings ;
2072
2069
if ( scopeDirective && elementControllers [ scopeDirective . name ] ) {
2073
2070
bindings = scopeDirective . $$bindings . bindToController ;
2074
2071
controller = elementControllers [ scopeDirective . name ] ;
2075
2072
2076
2073
if ( controller && controller . identifier && bindings ) {
2077
2074
controllerForBindings = controller ;
2078
- thisLinkFn . $$ destroyBindings =
2075
+ destroyBindings =
2079
2076
initializeDirectiveBindings ( scope , attrs , controller . instance ,
2080
- bindings , scopeDirective ) ;
2077
+ bindings , scopeDirective ) || noop ;
2081
2078
}
2082
2079
}
2083
2080
for ( i in elementControllers ) {
@@ -2091,8 +2088,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2091
2088
$element . data ( '$' + i + 'Controller' , controllerResult ) ;
2092
2089
if ( controller === controllerForBindings ) {
2093
2090
// Remove and re-install bindToController bindings
2094
- thisLinkFn . $$ destroyBindings( ) ;
2095
- thisLinkFn . $$ destroyBindings =
2091
+ destroyBindings ( ) ;
2092
+ destroyBindings =
2096
2093
initializeDirectiveBindings ( scope , attrs , controllerResult , bindings , scopeDirective ) ;
2097
2094
}
2098
2095
}
@@ -2354,7 +2351,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2354
2351
childBoundTranscludeFn = boundTranscludeFn ;
2355
2352
}
2356
2353
afterTemplateNodeLinkFn ( afterTemplateChildLinkFn , scope , linkNode , $rootElement ,
2357
- childBoundTranscludeFn , afterTemplateNodeLinkFn ) ;
2354
+ childBoundTranscludeFn ) ;
2358
2355
}
2359
2356
linkQueue = null ;
2360
2357
} ) ;
@@ -2371,8 +2368,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2371
2368
if ( afterTemplateNodeLinkFn . transcludeOnThisElement ) {
2372
2369
childBoundTranscludeFn = createBoundTranscludeFn ( scope , afterTemplateNodeLinkFn . transclude , boundTranscludeFn ) ;
2373
2370
}
2374
- afterTemplateNodeLinkFn ( afterTemplateChildLinkFn , scope , node , rootElement , childBoundTranscludeFn ,
2375
- afterTemplateNodeLinkFn ) ;
2371
+ afterTemplateNodeLinkFn ( afterTemplateChildLinkFn , scope , node , rootElement , childBoundTranscludeFn ) ;
2376
2372
}
2377
2373
} ;
2378
2374
}
@@ -2632,8 +2628,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2632
2628
2633
2629
// Set up $watches for isolate scope and controller bindings. This process
2634
2630
// only occurs for isolate scopes and new scopes with controllerAs.
2635
- function initializeDirectiveBindings ( scope , attrs , destination , bindings ,
2636
- directive , newScope ) {
2631
+ function initializeDirectiveBindings ( scope , attrs , destination , bindings , directive ) {
2637
2632
var onNewScopeDestroyed ;
2638
2633
forEach ( bindings , function ( definition , scopeName ) {
2639
2634
var attrName = definition . attrName ,
@@ -2719,16 +2714,12 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2719
2714
break ;
2720
2715
}
2721
2716
} ) ;
2722
- var destroyBindings = onNewScopeDestroyed ? function destroyBindings ( ) {
2717
+
2718
+ return onNewScopeDestroyed && function destroyBindings ( ) {
2723
2719
for ( var i = 0 , ii = onNewScopeDestroyed . length ; i < ii ; ++ i ) {
2724
2720
onNewScopeDestroyed [ i ] ( ) ;
2725
2721
}
2726
- } : noop ;
2727
- if ( newScope && destroyBindings !== noop ) {
2728
- newScope . $on ( '$destroy' , destroyBindings ) ;
2729
- return noop ;
2730
- }
2731
- return destroyBindings ;
2722
+ } ;
2732
2723
}
2733
2724
} ] ;
2734
2725
}
0 commit comments