@@ -362,7 +362,7 @@ function $CompileProvider($provide) {
362
362
363
363
//================================
364
364
365
- function compile ( $compileNodes , transcludeFn , maxPriority ) {
365
+ function compile ( $compileNodes , transcludeFn , maxPriority , ignoreDirective ) {
366
366
if ( ! ( $compileNodes instanceof jqLite ) ) {
367
367
// jquery always rewraps, whereas we need to preserve the original selector so that we can modify it.
368
368
$compileNodes = jqLite ( $compileNodes ) ;
@@ -375,7 +375,7 @@ function $CompileProvider($provide) {
375
375
$compileNodes [ index ] = node = jqLite ( node ) . wrap ( '<span></span>' ) . parent ( ) [ 0 ] ;
376
376
}
377
377
} ) ;
378
- var compositeLinkFn = compileNodes ( $compileNodes , transcludeFn , $compileNodes , maxPriority ) ;
378
+ var compositeLinkFn = compileNodes ( $compileNodes , transcludeFn , $compileNodes , maxPriority , ignoreDirective ) ;
379
379
return function publicLinkFn ( scope , cloneConnectFn ) {
380
380
assertArg ( scope , 'scope' ) ;
381
381
// important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
@@ -422,15 +422,15 @@ function $CompileProvider($provide) {
422
422
* @param {number= } max directive priority
423
423
* @returns {?function } A composite linking function of all of the matched directives or null.
424
424
*/
425
- function compileNodes ( nodeList , transcludeFn , $rootElement , maxPriority ) {
425
+ function compileNodes ( nodeList , transcludeFn , $rootElement , maxPriority , ignoreDirective ) {
426
426
var linkFns = [ ] ,
427
427
nodeLinkFn , childLinkFn , directives , attrs , linkFnFound ;
428
428
429
429
for ( var i = 0 ; i < nodeList . length ; i ++ ) {
430
430
attrs = new Attributes ( ) ;
431
431
432
432
// we must always refer to nodeList[i] since the nodes can be replaced underneath us.
433
- directives = collectDirectives ( nodeList [ i ] , [ ] , attrs , i == 0 ? maxPriority : undefined ) ;
433
+ directives = collectDirectives ( nodeList [ i ] , [ ] , attrs , i == 0 ? maxPriority : undefined , ignoreDirective ) ;
434
434
435
435
nodeLinkFn = ( directives . length )
436
436
? applyDirectivesToNode ( directives , nodeList [ i ] , attrs , transcludeFn , $rootElement )
@@ -504,7 +504,7 @@ function $CompileProvider($provide) {
504
504
* @param attrs The shared attrs object which is used to populate the normalized attributes.
505
505
* @param {number= } maxPriority Max directive priority.
506
506
*/
507
- function collectDirectives ( node , directives , attrs , maxPriority ) {
507
+ function collectDirectives ( node , directives , attrs , maxPriority , ignoreDirective ) {
508
508
var nodeType = node . nodeType ,
509
509
attrsMap = attrs . $attr ,
510
510
match ,
@@ -514,7 +514,7 @@ function $CompileProvider($provide) {
514
514
case 1 : /* Element */
515
515
// use the node name: <directive>
516
516
addDirective ( directives ,
517
- directiveNormalize ( nodeName_ ( node ) . toLowerCase ( ) ) , 'E' , maxPriority ) ;
517
+ directiveNormalize ( nodeName_ ( node ) . toLowerCase ( ) ) , 'E' , maxPriority , ignoreDirective ) ;
518
518
519
519
// iterate over the attributes
520
520
for ( var attr , name , nName , ngAttrName , value , nAttrs = node . attributes ,
@@ -545,7 +545,7 @@ function $CompileProvider($provide) {
545
545
attrs [ nName ] = true ; // presence means true
546
546
}
547
547
addAttrInterpolateDirective ( node , directives , value , nName ) ;
548
- addDirective ( directives , nName , 'A' , maxPriority , attrStartName , attrEndName ) ;
548
+ addDirective ( directives , nName , 'A' , maxPriority , ignoreDirective , attrStartName , attrEndName ) ;
549
549
}
550
550
}
551
551
@@ -554,7 +554,7 @@ function $CompileProvider($provide) {
554
554
if ( isString ( className ) && className !== '' ) {
555
555
while ( match = CLASS_DIRECTIVE_REGEXP . exec ( className ) ) {
556
556
nName = directiveNormalize ( match [ 2 ] ) ;
557
- if ( addDirective ( directives , nName , 'C' , maxPriority ) ) {
557
+ if ( addDirective ( directives , nName , 'C' , maxPriority , ignoreDirective ) ) {
558
558
attrs [ nName ] = trim ( match [ 3 ] ) ;
559
559
}
560
560
className = className . substr ( match . index + match [ 0 ] . length ) ;
@@ -569,7 +569,7 @@ function $CompileProvider($provide) {
569
569
match = COMMENT_DIRECTIVE_REGEXP . exec ( node . nodeValue ) ;
570
570
if ( match ) {
571
571
nName = directiveNormalize ( match [ 1 ] ) ;
572
- if ( addDirective ( directives , nName , 'M' , maxPriority ) ) {
572
+ if ( addDirective ( directives , nName , 'M' , maxPriority , ignoreDirective ) ) {
573
573
attrs [ nName ] = trim ( match [ 2 ] ) ;
574
574
}
575
575
}
@@ -643,7 +643,7 @@ function $CompileProvider($provide) {
643
643
* argument has the root jqLite array so that we can replace nodes on it.
644
644
* @returns linkFn
645
645
*/
646
- function applyDirectivesToNode ( directives , compileNode , templateAttrs , transcludeFn , jqCollection ) {
646
+ function applyDirectivesToNode ( directives , compileNode , templateAttrs , transcludeFn , jqCollection , originalReplaceDirective ) {
647
647
var terminalPriority = - Number . MAX_VALUE ,
648
648
preLinkFns = [ ] ,
649
649
postLinkFns = [ ] ,
@@ -655,6 +655,7 @@ function $CompileProvider($provide) {
655
655
directiveName ,
656
656
$template ,
657
657
transcludeDirective ,
658
+ replaceDirective = originalReplaceDirective ,
658
659
childTranscludeFn = transcludeFn ,
659
660
controllerDirectives ,
660
661
linkFn ,
@@ -705,7 +706,9 @@ function $CompileProvider($provide) {
705
706
jqLite ( document . createComment ( ' ' + directiveName + ': ' + templateAttrs [ directiveName ] + ' ' ) ) ;
706
707
compileNode = $compileNode [ 0 ] ;
707
708
replaceWith ( jqCollection , jqLite ( sliceArgs ( $template ) ) , compileNode ) ;
708
- childTranscludeFn = compile ( $template , transcludeFn , terminalPriority ) ;
709
+
710
+ childTranscludeFn = compile ( $template , transcludeFn , terminalPriority ,
711
+ replaceDirective && replaceDirective . name ) ;
709
712
} else {
710
713
$template = jqLite ( JQLiteClone ( compileNode ) ) . contents ( ) ;
711
714
$compileNode . html ( '' ) ; // clear contents
@@ -724,6 +727,7 @@ function $CompileProvider($provide) {
724
727
directiveValue = denormalizeTemplate ( directiveValue ) ;
725
728
726
729
if ( directive . replace ) {
730
+ replaceDirective = directive ;
727
731
$template = jqLite ( '<div>' +
728
732
trim ( directiveValue ) +
729
733
'</div>' ) . contents ( ) ;
@@ -760,9 +764,12 @@ function $CompileProvider($provide) {
760
764
if ( directive . templateUrl ) {
761
765
assertNoDuplicate ( 'template' , templateDirective , directive , $compileNode ) ;
762
766
templateDirective = directive ;
767
+
768
+ if ( directive . replace ) {
769
+ replaceDirective = directive ;
770
+ }
763
771
nodeLinkFn = compileTemplateUrl ( directives . splice ( i , directives . length - i ) ,
764
- nodeLinkFn , $compileNode , templateAttrs , jqCollection , directive . replace ,
765
- childTranscludeFn ) ;
772
+ nodeLinkFn , $compileNode , templateAttrs , jqCollection , childTranscludeFn ) ;
766
773
ii = directives . length ;
767
774
} else if ( directive . compile ) {
768
775
try {
@@ -978,7 +985,8 @@ function $CompileProvider($provide) {
978
985
* * `M`: comment
979
986
* @returns true if directive was added.
980
987
*/
981
- function addDirective ( tDirectives , name , location , maxPriority , startAttrName , endAttrName ) {
988
+ function addDirective ( tDirectives , name , location , maxPriority , ignoreDirective , startAttrName , endAttrName ) {
989
+ if ( name === ignoreDirective ) return null ;
982
990
var match = null ;
983
991
if ( hasDirectives . hasOwnProperty ( name ) ) {
984
992
for ( var directive , directives = $injector . get ( name + Suffix ) ,
@@ -1039,15 +1047,15 @@ function $CompileProvider($provide) {
1039
1047
1040
1048
1041
1049
function compileTemplateUrl ( directives , beforeTemplateNodeLinkFn , $compileNode , tAttrs ,
1042
- $rootElement , replace , childTranscludeFn ) {
1050
+ $rootElement , childTranscludeFn ) {
1043
1051
var linkQueue = [ ] ,
1044
1052
afterTemplateNodeLinkFn ,
1045
1053
afterTemplateChildLinkFn ,
1046
1054
beforeTemplateCompileNode = $compileNode [ 0 ] ,
1047
1055
origAsyncDirective = directives . shift ( ) ,
1048
1056
// The fact that we have to copy and patch the directive seems wrong!
1049
1057
derivedSyncDirective = extend ( { } , origAsyncDirective , {
1050
- controller : null , templateUrl : null , transclude : null , scope : null
1058
+ controller : null , templateUrl : null , transclude : null , scope : null , replace : null
1051
1059
} ) ,
1052
1060
templateUrl = ( isFunction ( origAsyncDirective . templateUrl ) )
1053
1061
? origAsyncDirective . templateUrl ( $compileNode , tAttrs )
@@ -1061,7 +1069,7 @@ function $CompileProvider($provide) {
1061
1069
1062
1070
content = denormalizeTemplate ( content ) ;
1063
1071
1064
- if ( replace ) {
1072
+ if ( origAsyncDirective . replace ) {
1065
1073
$template = jqLite ( '<div>' + trim ( content ) + '</div>' ) . contents ( ) ;
1066
1074
compileNode = $template [ 0 ] ;
1067
1075
@@ -1080,7 +1088,8 @@ function $CompileProvider($provide) {
1080
1088
}
1081
1089
1082
1090
directives . unshift ( derivedSyncDirective ) ;
1083
- afterTemplateNodeLinkFn = applyDirectivesToNode ( directives , compileNode , tAttrs , childTranscludeFn , $compileNode ) ;
1091
+
1092
+ afterTemplateNodeLinkFn = applyDirectivesToNode ( directives , compileNode , tAttrs , childTranscludeFn , $compileNode , origAsyncDirective ) ;
1084
1093
forEach ( $rootElement , function ( node , i ) {
1085
1094
if ( node == compileNode ) {
1086
1095
$rootElement [ i ] = $compileNode [ 0 ] ;
0 commit comments