@@ -956,12 +956,14 @@ function $CompileProvider($provide) {
956
956
957
957
function createBoundTranscludeFn ( scope , transcludeFn ) {
958
958
return function boundTranscludeFn ( transcludedScope , cloneFn , controllers ) {
959
- var scopeCreated ;
959
+ var scopeCreated = false ;
960
+
960
961
if ( ! transcludedScope ) {
961
962
transcludedScope = scope . $new ( ) ;
962
963
transcludedScope . $$transcluded = true ;
963
964
scopeCreated = true ;
964
965
}
966
+
965
967
var clone = transcludeFn ( transcludedScope , cloneFn , controllers ) ;
966
968
if ( scopeCreated ) {
967
969
clone . on ( '$destroy' , bind ( transcludedScope , transcludedScope . $destroy ) ) ;
@@ -1381,7 +1383,7 @@ function $CompileProvider($provide) {
1381
1383
1382
1384
1383
1385
function nodeLinkFn ( childLinkFn , scope , linkNode , $rootElement , boundTranscludeFn ) {
1384
- var attrs , $element , i , ii , linkFn , controller , isolateScope , elementControllers = { } , $transclude ;
1386
+ var attrs , $element , i , ii , linkFn , controller , isolateScope , elementControllers = { } , transcludeFn ;
1385
1387
1386
1388
if ( compileNode === linkNode ) {
1387
1389
attrs = templateAttrs ;
@@ -1475,14 +1477,14 @@ function $CompileProvider($provide) {
1475
1477
}
1476
1478
} ) ;
1477
1479
}
1478
- $transclude = boundTranscludeFn && controllerBoundTransclude ;
1480
+ transcludeFn = boundTranscludeFn && controllersBoundTransclude ;
1479
1481
if ( controllerDirectives ) {
1480
1482
forEach ( controllerDirectives , function ( directive ) {
1481
1483
var locals = {
1482
1484
$scope : directive === newIsolateScopeDirective || directive . $$isolateScope ? isolateScope : scope ,
1483
1485
$element : $element ,
1484
1486
$attrs : attrs ,
1485
- $transclude : $transclude
1487
+ $transclude : transcludeFn
1486
1488
} , controllerInstance ;
1487
1489
1488
1490
controller = directive . controller ;
@@ -1492,9 +1494,10 @@ function $CompileProvider($provide) {
1492
1494
1493
1495
controllerInstance = $controller ( controller , locals ) ;
1494
1496
// For directives with element transclusion the element is a comment,
1495
- // but jQuery .data doesn't support
1496
- // attaching data to comment nodes as it's hard to clean up (http://bugs.jquery.com/ticket/8335)
1497
- // so instead we save the direct controllers for the element in a local hash.
1497
+ // but jQuery .data doesn't support attaching data to comment nodes as it's hard to
1498
+ // clean up (http://bugs.jquery.com/ticket/8335).
1499
+ // Instead, we save the controllers for the element in a local hash and attach to .data
1500
+ // later, once we have the actual element.
1498
1501
elementControllers [ directive . name ] = controllerInstance ;
1499
1502
if ( ! hasElementTranscludeDirective ) {
1500
1503
$element . data ( '$' + directive . name + 'Controller' , controllerInstance ) ;
@@ -1511,7 +1514,7 @@ function $CompileProvider($provide) {
1511
1514
try {
1512
1515
linkFn = preLinkFns [ i ] ;
1513
1516
linkFn ( linkFn . isolateScope ? isolateScope : scope , $element , attrs ,
1514
- linkFn . require && getControllers ( linkFn . require , $element , elementControllers ) , $transclude ) ;
1517
+ linkFn . require && getControllers ( linkFn . require , $element , elementControllers ) , transcludeFn ) ;
1515
1518
} catch ( e ) {
1516
1519
$exceptionHandler ( e , startingTag ( $element ) ) ;
1517
1520
}
@@ -1531,28 +1534,26 @@ function $CompileProvider($provide) {
1531
1534
try {
1532
1535
linkFn = postLinkFns [ i ] ;
1533
1536
linkFn ( linkFn . isolateScope ? isolateScope : scope , $element , attrs ,
1534
- linkFn . require && getControllers ( linkFn . require , $element , elementControllers ) , $transclude ) ;
1537
+ linkFn . require && getControllers ( linkFn . require , $element , elementControllers ) , transcludeFn ) ;
1535
1538
} catch ( e ) {
1536
1539
$exceptionHandler ( e , startingTag ( $element ) ) ;
1537
1540
}
1538
1541
}
1539
1542
1540
- function controllerBoundTransclude ( ) {
1541
- var scope , cloneAttachFn , transcludeControllers ;
1542
- if ( ! boundTranscludeFn ) {
1543
- return ;
1544
- }
1543
+ // This is the function that is injected as `$transclude`.
1544
+ function controllersBoundTransclude ( scope , cloneAttachFn ) {
1545
+ var transcludeControllers ;
1546
+
1547
+ // no scope passed
1545
1548
if ( arguments . length < 2 ) {
1546
- // no scope but cloneAttachFn
1547
- cloneAttachFn = arguments [ 0 ] ;
1548
- } else {
1549
- // scope and cloneAttachFn (e.g. for ngIf)
1550
- scope = arguments [ 0 ] ;
1551
- cloneAttachFn = arguments [ 1 ] ;
1549
+ cloneAttachFn = scope ;
1550
+ scope = undefined ;
1552
1551
}
1552
+
1553
1553
if ( hasElementTranscludeDirective ) {
1554
1554
transcludeControllers = elementControllers ;
1555
1555
}
1556
+
1556
1557
return boundTranscludeFn ( scope , cloneAttachFn , transcludeControllers ) ;
1557
1558
}
1558
1559
}
0 commit comments