@@ -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 ) ;
@@ -1971,8 +1965,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1971
1965
return elementControllers ;
1972
1966
}
1973
1967
1974
- function nodeLinkFn ( childLinkFn , scope , linkNode , $rootElement , boundTranscludeFn ,
1975
- thisLinkFn ) {
1968
+ function nodeLinkFn ( childLinkFn , scope , linkNode , $rootElement , boundTranscludeFn ) {
1976
1969
var i , ii , linkFn , controller , isolateScope , elementControllers , transcludeFn , $element ,
1977
1970
attrs ;
1978
1971
@@ -2006,24 +1999,28 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2006
1999
compile . $$addScopeClass ( $element , true ) ;
2007
2000
isolateScope . $$isolateBindings =
2008
2001
newIsolateScopeDirective . $$isolateBindings ;
2009
- initializeDirectiveBindings ( scope , attrs , isolateScope ,
2010
- isolateScope . $$isolateBindings ,
2011
- newIsolateScopeDirective , isolateScope ) ;
2002
+ var parentWatchDestroyer = initializeDirectiveBindings ( scope , attrs , isolateScope ,
2003
+ isolateScope . $$isolateBindings ,
2004
+ newIsolateScopeDirective ) ;
2005
+ if ( parentWatchDestroyer ) {
2006
+ isolateScope . $on ( '$destroy' , parentWatchDestroyer ) ;
2007
+ }
2012
2008
}
2013
2009
if ( elementControllers ) {
2014
2010
// Initialize bindToController bindings for new/isolate scopes
2015
2011
var scopeDirective = newIsolateScopeDirective || newScopeDirective ;
2016
2012
var bindings ;
2017
2013
var controllerForBindings ;
2014
+ var destroyBindings ;
2018
2015
if ( scopeDirective && elementControllers [ scopeDirective . name ] ) {
2019
2016
bindings = scopeDirective . $$bindings . bindToController ;
2020
2017
controller = elementControllers [ scopeDirective . name ] ;
2021
2018
2022
2019
if ( controller && controller . identifier && bindings ) {
2023
2020
controllerForBindings = controller ;
2024
- thisLinkFn . $$ destroyBindings =
2021
+ destroyBindings =
2025
2022
initializeDirectiveBindings ( scope , attrs , controller . instance ,
2026
- bindings , scopeDirective ) ;
2023
+ bindings , scopeDirective ) || noop ;
2027
2024
}
2028
2025
}
2029
2026
for ( i in elementControllers ) {
@@ -2037,8 +2034,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2037
2034
$element . data ( '$' + i + 'Controller' , controllerResult ) ;
2038
2035
if ( controller === controllerForBindings ) {
2039
2036
// Remove and re-install bindToController bindings
2040
- thisLinkFn . $$ destroyBindings( ) ;
2041
- thisLinkFn . $$ destroyBindings =
2037
+ destroyBindings ( ) ;
2038
+ destroyBindings =
2042
2039
initializeDirectiveBindings ( scope , attrs , controllerResult , bindings , scopeDirective ) ;
2043
2040
}
2044
2041
}
@@ -2300,7 +2297,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2300
2297
childBoundTranscludeFn = boundTranscludeFn ;
2301
2298
}
2302
2299
afterTemplateNodeLinkFn ( afterTemplateChildLinkFn , scope , linkNode , $rootElement ,
2303
- childBoundTranscludeFn , afterTemplateNodeLinkFn ) ;
2300
+ childBoundTranscludeFn ) ;
2304
2301
}
2305
2302
linkQueue = null ;
2306
2303
} ) ;
@@ -2317,8 +2314,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2317
2314
if ( afterTemplateNodeLinkFn . transcludeOnThisElement ) {
2318
2315
childBoundTranscludeFn = createBoundTranscludeFn ( scope , afterTemplateNodeLinkFn . transclude , boundTranscludeFn ) ;
2319
2316
}
2320
- afterTemplateNodeLinkFn ( afterTemplateChildLinkFn , scope , node , rootElement , childBoundTranscludeFn ,
2321
- afterTemplateNodeLinkFn ) ;
2317
+ afterTemplateNodeLinkFn ( afterTemplateChildLinkFn , scope , node , rootElement , childBoundTranscludeFn ) ;
2322
2318
}
2323
2319
} ;
2324
2320
}
@@ -2578,8 +2574,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2578
2574
2579
2575
// Set up $watches for isolate scope and controller bindings. This process
2580
2576
// only occurs for isolate scopes and new scopes with controllerAs.
2581
- function initializeDirectiveBindings ( scope , attrs , destination , bindings ,
2582
- directive , newScope ) {
2577
+ function initializeDirectiveBindings ( scope , attrs , destination , bindings , directive ) {
2583
2578
var onNewScopeDestroyed ;
2584
2579
forEach ( bindings , function ( definition , scopeName ) {
2585
2580
var attrName = definition . attrName ,
@@ -2665,16 +2660,12 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2665
2660
break ;
2666
2661
}
2667
2662
} ) ;
2668
- var destroyBindings = onNewScopeDestroyed ? function destroyBindings ( ) {
2663
+
2664
+ return onNewScopeDestroyed && function destroyBindings ( ) {
2669
2665
for ( var i = 0 , ii = onNewScopeDestroyed . length ; i < ii ; ++ i ) {
2670
2666
onNewScopeDestroyed [ i ] ( ) ;
2671
2667
}
2672
- } : noop ;
2673
- if ( newScope && destroyBindings !== noop ) {
2674
- newScope . $on ( '$destroy' , destroyBindings ) ;
2675
- return noop ;
2676
- }
2677
- return destroyBindings ;
2668
+ } ;
2678
2669
}
2679
2670
} ] ;
2680
2671
}
0 commit comments