@@ -468,7 +468,7 @@ function $CompileProvider($provide) {
468
468
469
469
//================================
470
470
471
- function compile ( $compileNodes , transcludeFn , maxPriority , ignoreDirective ) {
471
+ function compile ( $compileNodes , transcludeFn , maxPriority , ignoreDirective , previousCompileContext ) {
472
472
if ( ! ( $compileNodes instanceof jqLite ) ) {
473
473
// jquery always rewraps, whereas we need to preserve the original selector so that we can modify it.
474
474
$compileNodes = jqLite ( $compileNodes ) ;
@@ -480,7 +480,7 @@ function $CompileProvider($provide) {
480
480
$compileNodes [ index ] = node = jqLite ( node ) . wrap ( '<span></span>' ) . parent ( ) [ 0 ] ;
481
481
}
482
482
} ) ;
483
- var compositeLinkFn = compileNodes ( $compileNodes , transcludeFn , $compileNodes , maxPriority , ignoreDirective ) ;
483
+ var compositeLinkFn = compileNodes ( $compileNodes , transcludeFn , $compileNodes , maxPriority , ignoreDirective , previousCompileContext ) ;
484
484
return function publicLinkFn ( scope , cloneConnectFn ) {
485
485
assertArg ( scope , 'scope' ) ;
486
486
// important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
@@ -527,7 +527,7 @@ function $CompileProvider($provide) {
527
527
* @param {number= } max directive priority
528
528
* @returns {?function } A composite linking function of all of the matched directives or null.
529
529
*/
530
- function compileNodes ( nodeList , transcludeFn , $rootElement , maxPriority , ignoreDirective ) {
530
+ function compileNodes ( nodeList , transcludeFn , $rootElement , maxPriority , ignoreDirective , previousCompileContext ) {
531
531
var linkFns = [ ] ,
532
532
nodeLinkFn , childLinkFn , directives , attrs , linkFnFound ;
533
533
@@ -538,7 +538,7 @@ function $CompileProvider($provide) {
538
538
directives = collectDirectives ( nodeList [ i ] , [ ] , attrs , i == 0 ? maxPriority : undefined , ignoreDirective ) ;
539
539
540
540
nodeLinkFn = ( directives . length )
541
- ? applyDirectivesToNode ( directives , nodeList [ i ] , attrs , transcludeFn , $rootElement , null , [ ] , [ ] )
541
+ ? applyDirectivesToNode ( directives , nodeList [ i ] , attrs , transcludeFn , $rootElement , null , [ ] , [ ] , previousCompileContext )
542
542
: null ;
543
543
544
544
childLinkFn = ( nodeLinkFn && nodeLinkFn . terminal || ! nodeList [ i ] . childNodes || ! nodeList [ i ] . childNodes . length )
@@ -549,6 +549,7 @@ function $CompileProvider($provide) {
549
549
linkFns . push ( nodeLinkFn ) ;
550
550
linkFns . push ( childLinkFn ) ;
551
551
linkFnFound = ( linkFnFound || nodeLinkFn || childLinkFn ) ;
552
+ previousCompileContext = null ; //use the previous context only for the first element in the virtual group
552
553
}
553
554
554
555
// return a linking function if we have found anything, null otherwise
@@ -749,23 +750,26 @@ function $CompileProvider($provide) {
749
750
* scope argument is auto-generated to the new child of the transcluded parent scope.
750
751
* @param {JQLite } jqCollection If we are working on the root of the compile tree then this
751
752
* argument has the root jqLite array so that we can replace nodes on it.
752
- * @param {Object= } ignoreDirective An optional directive that will be ignored when compiling
753
+ * @param {Object= } originalReplaceDirective An optional directive that will be ignored when compiling
753
754
* the transclusion.
754
755
* @param {Array.<Function> } preLinkFns
755
756
* @param {Array.<Function> } postLinkFns
757
+ * @param {Object } previousCompileContext Context used for previous compilation of the current node
756
758
* @returns linkFn
757
759
*/
758
760
function applyDirectivesToNode ( directives , compileNode , templateAttrs , transcludeFn , jqCollection ,
759
- originalReplaceDirective , preLinkFns , postLinkFns ) {
761
+ originalReplaceDirective , preLinkFns , postLinkFns , previousCompileContext ) {
762
+ previousCompileContext = previousCompileContext || { } ;
763
+
760
764
var terminalPriority = - Number . MAX_VALUE ,
761
- newScopeDirective = null ,
762
- newIsolateScopeDirective = null ,
763
- templateDirective = null ,
765
+ newScopeDirective ,
766
+ newIsolateScopeDirective = previousCompileContext . newIsolateScopeDirective ,
767
+ templateDirective = previousCompileContext . templateDirective ,
764
768
$compileNode = templateAttrs . $$element = jqLite ( compileNode ) ,
765
769
directive ,
766
770
directiveName ,
767
771
$template ,
768
- transcludeDirective ,
772
+ transcludeDirective = previousCompileContext . transcludeDirective ,
769
773
replaceDirective = originalReplaceDirective ,
770
774
childTranscludeFn = transcludeFn ,
771
775
controllerDirectives ,
@@ -814,19 +818,27 @@ function $CompileProvider($provide) {
814
818
}
815
819
816
820
if ( directiveValue = directive . transclude ) {
817
- assertNoDuplicate ( 'transclusion' , transcludeDirective , directive , $compileNode ) ;
818
- transcludeDirective = directive ;
821
+ // Special case ngRepeat so that we don't complain about duplicate transclusion, ngRepeat knows how to handle
822
+ // this on its own.
823
+ if ( directiveName !== 'ngRepeat' ) {
824
+ assertNoDuplicate ( 'transclusion' , transcludeDirective , directive , $compileNode ) ;
825
+ transcludeDirective = directive ;
826
+ }
819
827
820
828
if ( directiveValue == 'element' ) {
821
829
terminalPriority = directive . priority ;
822
- $template = groupScan ( compileNode , attrStart , attrEnd )
830
+ $template = groupScan ( compileNode , attrStart , attrEnd ) ;
823
831
$compileNode = templateAttrs . $$element =
824
832
jqLite ( document . createComment ( ' ' + directiveName + ': ' + templateAttrs [ directiveName ] + ' ' ) ) ;
825
833
compileNode = $compileNode [ 0 ] ;
826
834
replaceWith ( jqCollection , jqLite ( sliceArgs ( $template ) ) , compileNode ) ;
827
835
828
836
childTranscludeFn = compile ( $template , transcludeFn , terminalPriority ,
829
- replaceDirective && replaceDirective . name ) ;
837
+ replaceDirective && replaceDirective . name , {
838
+ newIsolateScopeDirective : newIsolateScopeDirective ,
839
+ transcludeDirective : transcludeDirective ,
840
+ templateDirective : templateDirective
841
+ } ) ;
830
842
} else {
831
843
$template = jqLite ( JQLiteClone ( compileNode ) ) . contents ( ) ;
832
844
$compileNode . html ( '' ) ; // clear contents
0 commit comments