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