@@ -1416,11 +1416,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1416
1416
if ( nodeLinkFn . scope ) {
1417
1417
childScope = scope . $new ( ) ;
1418
1418
compile . $$addScopeInfo ( jqLite ( node ) , childScope ) ;
1419
- var destroyBindings = nodeLinkFn . $$destroyBindings ;
1420
- if ( destroyBindings ) {
1421
- nodeLinkFn . $$destroyBindings = null ;
1422
- childScope . $on ( '$destroyed' , destroyBindings ) ;
1423
- }
1424
1419
} else {
1425
1420
childScope = scope ;
1426
1421
}
@@ -1439,8 +1434,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1439
1434
childBoundTranscludeFn = null ;
1440
1435
}
1441
1436
1442
- nodeLinkFn ( childLinkFn , childScope , node , $rootElement , childBoundTranscludeFn ,
1443
- nodeLinkFn ) ;
1437
+ nodeLinkFn ( childLinkFn , childScope , node , $rootElement , childBoundTranscludeFn ) ;
1444
1438
1445
1439
} else if ( childLinkFn ) {
1446
1440
childLinkFn ( scope , node . childNodes , undefined , parentBoundTranscludeFn ) ;
@@ -1950,8 +1944,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1950
1944
return elementControllers ;
1951
1945
}
1952
1946
1953
- function nodeLinkFn ( childLinkFn , scope , linkNode , $rootElement , boundTranscludeFn ,
1954
- thisLinkFn ) {
1947
+ function nodeLinkFn ( childLinkFn , scope , linkNode , $rootElement , boundTranscludeFn ) {
1955
1948
var i , ii , linkFn , controller , isolateScope , elementControllers , transcludeFn , $element ,
1956
1949
attrs ;
1957
1950
@@ -1985,24 +1978,28 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1985
1978
compile . $$addScopeClass ( $element , true ) ;
1986
1979
isolateScope . $$isolateBindings =
1987
1980
newIsolateScopeDirective . $$isolateBindings ;
1988
- initializeDirectiveBindings ( scope , attrs , isolateScope ,
1989
- isolateScope . $$isolateBindings ,
1990
- newIsolateScopeDirective , isolateScope ) ;
1981
+ var parentWatchDestoryer = initializeDirectiveBindings ( scope , attrs , isolateScope ,
1982
+ isolateScope . $$isolateBindings ,
1983
+ newIsolateScopeDirective ) ;
1984
+ if ( parentWatchDestoryer ) {
1985
+ isolateScope . $on ( '$destroy' , parentWatchDestoryer ) ;
1986
+ }
1991
1987
}
1992
1988
if ( elementControllers ) {
1993
1989
// Initialize bindToController bindings for new/isolate scopes
1994
1990
var scopeDirective = newIsolateScopeDirective || newScopeDirective ;
1995
1991
var bindings ;
1996
1992
var controllerForBindings ;
1993
+ var destroyBindings ;
1997
1994
if ( scopeDirective && elementControllers [ scopeDirective . name ] ) {
1998
1995
bindings = scopeDirective . $$bindings . bindToController ;
1999
1996
controller = elementControllers [ scopeDirective . name ] ;
2000
1997
2001
1998
if ( controller && controller . identifier && bindings ) {
2002
1999
controllerForBindings = controller ;
2003
- thisLinkFn . $$ destroyBindings =
2000
+ destroyBindings =
2004
2001
initializeDirectiveBindings ( scope , attrs , controller . instance ,
2005
- bindings , scopeDirective ) ;
2002
+ bindings , scopeDirective ) || noop ;
2006
2003
}
2007
2004
}
2008
2005
for ( i in elementControllers ) {
@@ -2016,8 +2013,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2016
2013
$element . data ( '$' + i + 'Controller' , controllerResult ) ;
2017
2014
if ( controller === controllerForBindings ) {
2018
2015
// Remove and re-install bindToController bindings
2019
- thisLinkFn . $$ destroyBindings( ) ;
2020
- thisLinkFn . $$ destroyBindings =
2016
+ destroyBindings ( ) ;
2017
+ destroyBindings =
2021
2018
initializeDirectiveBindings ( scope , attrs , controllerResult , bindings , scopeDirective ) ;
2022
2019
}
2023
2020
}
@@ -2279,7 +2276,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2279
2276
childBoundTranscludeFn = boundTranscludeFn ;
2280
2277
}
2281
2278
afterTemplateNodeLinkFn ( afterTemplateChildLinkFn , scope , linkNode , $rootElement ,
2282
- childBoundTranscludeFn , afterTemplateNodeLinkFn ) ;
2279
+ childBoundTranscludeFn ) ;
2283
2280
}
2284
2281
linkQueue = null ;
2285
2282
} ) ;
@@ -2296,8 +2293,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2296
2293
if ( afterTemplateNodeLinkFn . transcludeOnThisElement ) {
2297
2294
childBoundTranscludeFn = createBoundTranscludeFn ( scope , afterTemplateNodeLinkFn . transclude , boundTranscludeFn ) ;
2298
2295
}
2299
- afterTemplateNodeLinkFn ( afterTemplateChildLinkFn , scope , node , rootElement , childBoundTranscludeFn ,
2300
- afterTemplateNodeLinkFn ) ;
2296
+ afterTemplateNodeLinkFn ( afterTemplateChildLinkFn , scope , node , rootElement , childBoundTranscludeFn ) ;
2301
2297
}
2302
2298
} ;
2303
2299
}
@@ -2557,8 +2553,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2557
2553
2558
2554
// Set up $watches for isolate scope and controller bindings. This process
2559
2555
// only occurs for isolate scopes and new scopes with controllerAs.
2560
- function initializeDirectiveBindings ( scope , attrs , destination , bindings ,
2561
- directive , newScope ) {
2556
+ function initializeDirectiveBindings ( scope , attrs , destination , bindings , directive ) {
2562
2557
var onNewScopeDestroyed ;
2563
2558
forEach ( bindings , function ( definition , scopeName ) {
2564
2559
var attrName = definition . attrName ,
@@ -2644,16 +2639,12 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2644
2639
break ;
2645
2640
}
2646
2641
} ) ;
2647
- var destroyBindings = onNewScopeDestroyed ? function destroyBindings ( ) {
2642
+
2643
+ return onNewScopeDestroyed && function destroyBindings ( ) {
2648
2644
for ( var i = 0 , ii = onNewScopeDestroyed . length ; i < ii ; ++ i ) {
2649
2645
onNewScopeDestroyed [ i ] ( ) ;
2650
2646
}
2651
- } : noop ;
2652
- if ( newScope && destroyBindings !== noop ) {
2653
- newScope . $on ( '$destroy' , destroyBindings ) ;
2654
- return noop ;
2655
- }
2656
- return destroyBindings ;
2647
+ } ;
2657
2648
}
2658
2649
} ] ;
2659
2650
}
0 commit comments