@@ -6596,6 +6596,27 @@ describe('$compile', function() {
6596
6596
} ) ;
6597
6597
} ) ;
6598
6598
6599
+ it ( 'should only allow one element transclusion per element when replace directive is in the mix' , function ( ) {
6600
+ module ( function ( ) {
6601
+ directive ( 'template' , valueFn ( {
6602
+ template : '<p second></p>' ,
6603
+ replace : true
6604
+ } ) ) ;
6605
+ directive ( 'first' , valueFn ( {
6606
+ transclude : 'element' ,
6607
+ priority : 100
6608
+ } ) ) ;
6609
+ directive ( 'second' , valueFn ( {
6610
+ transclude : 'element'
6611
+ } ) ) ;
6612
+ } ) ;
6613
+ inject ( function ( $compile ) {
6614
+ expect ( function ( ) {
6615
+ $compile ( '<div template first></div>' ) ;
6616
+ } ) . toThrowMinErr ( '$compile' , 'multidir' , / M u l t i p l e d i r e c t i v e s \[ f i r s t , s e c o n d \] a s k i n g f o r t r a n s c l u s i o n o n : < p .+ / ) ;
6617
+ } ) ;
6618
+ } ) ;
6619
+
6599
6620
6600
6621
it ( 'should support transcluded element on root content' , function ( ) {
6601
6622
var comment ;
@@ -6892,6 +6913,192 @@ describe('$compile', function() {
6892
6913
} ) ;
6893
6914
6894
6915
} ) ;
6916
+
6917
+ it ( 'should lazily compile the contents of directives that are transcluded' , function ( ) {
6918
+ var innerCompilationCount = 0 , transclude ;
6919
+
6920
+ module ( function ( ) {
6921
+ directive ( 'trans' , valueFn ( {
6922
+ transclude : true ,
6923
+ controller : function ( $transclude ) {
6924
+ transclude = $transclude ;
6925
+ }
6926
+ } ) ) ;
6927
+
6928
+ directive ( 'inner' , valueFn ( {
6929
+ template : '<span>FooBar</span>' ,
6930
+ compile : function ( ) {
6931
+ innerCompilationCount += 1 ;
6932
+ }
6933
+ } ) ) ;
6934
+ } ) ;
6935
+
6936
+ inject ( function ( $compile , $rootScope ) {
6937
+ element = $compile ( '<trans><inner></inner></trans>' ) ( $rootScope ) ;
6938
+ expect ( innerCompilationCount ) . toBe ( 0 ) ;
6939
+ transclude ( function ( child ) { element . append ( child ) ; } ) ;
6940
+ expect ( innerCompilationCount ) . toBe ( 1 ) ;
6941
+ expect ( element . text ( ) ) . toBe ( 'FooBar' ) ;
6942
+ } ) ;
6943
+ } ) ;
6944
+
6945
+ it ( 'should lazily compile the contents of directives that are transcluded with a template' , function ( ) {
6946
+ var innerCompilationCount = 0 , transclude ;
6947
+
6948
+ module ( function ( ) {
6949
+ directive ( 'trans' , valueFn ( {
6950
+ transclude : true ,
6951
+ template : '<div>Baz</div>' ,
6952
+ controller : function ( $transclude ) {
6953
+ transclude = $transclude ;
6954
+ }
6955
+ } ) ) ;
6956
+
6957
+ directive ( 'inner' , valueFn ( {
6958
+ template : '<span>FooBar</span>' ,
6959
+ compile : function ( ) {
6960
+ innerCompilationCount += 1 ;
6961
+ }
6962
+ } ) ) ;
6963
+ } ) ;
6964
+
6965
+ inject ( function ( $compile , $rootScope ) {
6966
+ element = $compile ( '<trans><inner></inner></trans>' ) ( $rootScope ) ;
6967
+ expect ( innerCompilationCount ) . toBe ( 0 ) ;
6968
+ transclude ( function ( child ) { element . append ( child ) ; } ) ;
6969
+ expect ( innerCompilationCount ) . toBe ( 1 ) ;
6970
+ expect ( element . text ( ) ) . toBe ( 'BazFooBar' ) ;
6971
+ } ) ;
6972
+ } ) ;
6973
+
6974
+ it ( 'should lazily compile the contents of directives that are transcluded with a templateUrl' , function ( ) {
6975
+ var innerCompilationCount = 0 , transclude ;
6976
+
6977
+ module ( function ( ) {
6978
+ directive ( 'trans' , valueFn ( {
6979
+ transclude : true ,
6980
+ templateUrl : 'baz.html' ,
6981
+ controller : function ( $transclude ) {
6982
+ transclude = $transclude ;
6983
+ }
6984
+ } ) ) ;
6985
+
6986
+ directive ( 'inner' , valueFn ( {
6987
+ template : '<span>FooBar</span>' ,
6988
+ compile : function ( ) {
6989
+ innerCompilationCount += 1 ;
6990
+ }
6991
+ } ) ) ;
6992
+ } ) ;
6993
+
6994
+ inject ( function ( $compile , $rootScope , $httpBackend ) {
6995
+ $httpBackend . expectGET ( 'baz.html' ) . respond ( '<div>Baz</div>' ) ;
6996
+ element = $compile ( '<trans><inner></inner></trans>' ) ( $rootScope ) ;
6997
+ $httpBackend . flush ( ) ;
6998
+
6999
+ expect ( innerCompilationCount ) . toBe ( 0 ) ;
7000
+ transclude ( function ( child ) { element . append ( child ) ; } ) ;
7001
+ expect ( innerCompilationCount ) . toBe ( 1 ) ;
7002
+ expect ( element . text ( ) ) . toBe ( 'BazFooBar' ) ;
7003
+ } ) ;
7004
+ } ) ;
7005
+
7006
+ it ( 'should lazily compile the contents of directives that are transclude element' , function ( ) {
7007
+ var innerCompilationCount = 0 , transclude ;
7008
+
7009
+ module ( function ( ) {
7010
+ directive ( 'trans' , valueFn ( {
7011
+ transclude : 'element' ,
7012
+ controller : function ( $transclude ) {
7013
+ transclude = $transclude ;
7014
+ }
7015
+ } ) ) ;
7016
+
7017
+ directive ( 'inner' , valueFn ( {
7018
+ template : '<span>FooBar</span>' ,
7019
+ compile : function ( ) {
7020
+ innerCompilationCount += 1 ;
7021
+ }
7022
+ } ) ) ;
7023
+ } ) ;
7024
+
7025
+ inject ( function ( $compile , $rootScope ) {
7026
+ element = $compile ( '<div><trans><inner></inner></trans></div>' ) ( $rootScope ) ;
7027
+ expect ( innerCompilationCount ) . toBe ( 0 ) ;
7028
+ transclude ( function ( child ) { element . append ( child ) ; } ) ;
7029
+ expect ( innerCompilationCount ) . toBe ( 1 ) ;
7030
+ expect ( element . text ( ) ) . toBe ( 'FooBar' ) ;
7031
+ } ) ;
7032
+ } ) ;
7033
+
7034
+ it ( 'should lazily compile transcluded directives with ngIf on them' , function ( ) {
7035
+ var innerCompilationCount = 0 , outerCompilationCount = 0 , transclude ;
7036
+
7037
+ module ( function ( ) {
7038
+ directive ( 'outer' , valueFn ( {
7039
+ transclude : true ,
7040
+ compile : function ( ) {
7041
+ outerCompilationCount += 1 ;
7042
+ } ,
7043
+ controller : function ( $transclude ) {
7044
+ transclude = $transclude ;
7045
+ }
7046
+ } ) ) ;
7047
+
7048
+ directive ( 'inner' , valueFn ( {
7049
+ template : '<span>FooBar</span>' ,
7050
+ compile : function ( ) {
7051
+ innerCompilationCount += 1 ;
7052
+ }
7053
+ } ) ) ;
7054
+ } ) ;
7055
+
7056
+ inject ( function ( $compile , $rootScope ) {
7057
+ $rootScope . shouldCompile = false ;
7058
+
7059
+ element = $compile ( '<div><outer ng-if="shouldCompile"><inner></inner></outer></div>' ) ( $rootScope ) ;
7060
+ expect ( outerCompilationCount ) . toBe ( 0 ) ;
7061
+ expect ( innerCompilationCount ) . toBe ( 0 ) ;
7062
+ expect ( transclude ) . toBeUndefined ( ) ;
7063
+ $rootScope . $apply ( 'shouldCompile=true' ) ;
7064
+ expect ( outerCompilationCount ) . toBe ( 1 ) ;
7065
+ expect ( innerCompilationCount ) . toBe ( 0 ) ;
7066
+ expect ( transclude ) . toBeDefined ( ) ;
7067
+ transclude ( function ( child ) { element . append ( child ) ; } ) ;
7068
+ expect ( outerCompilationCount ) . toBe ( 1 ) ;
7069
+ expect ( innerCompilationCount ) . toBe ( 1 ) ;
7070
+ expect ( element . text ( ) ) . toBe ( 'FooBar' ) ;
7071
+ } ) ;
7072
+ } ) ;
7073
+
7074
+ it ( 'should eagerly compile multiple directives with transclusion and templateUrl/replace' , function ( ) {
7075
+ var innerCompilationCount = 0 ;
7076
+
7077
+ module ( function ( ) {
7078
+ directive ( 'outer' , valueFn ( {
7079
+ transclude : true
7080
+ } ) ) ;
7081
+
7082
+ directive ( 'outer' , valueFn ( {
7083
+ templateUrl : 'inner.html' ,
7084
+ replace : true
7085
+ } ) ) ;
7086
+
7087
+ directive ( 'inner' , valueFn ( {
7088
+ compile : function ( ) {
7089
+ innerCompilationCount += 1 ;
7090
+ }
7091
+ } ) ) ;
7092
+ } ) ;
7093
+
7094
+ inject ( function ( $compile , $rootScope , $httpBackend ) {
7095
+ $httpBackend . expectGET ( 'inner.html' ) . respond ( '<inner></inner>' ) ;
7096
+ element = $compile ( '<outer></outer>' ) ( $rootScope ) ;
7097
+ $httpBackend . flush ( ) ;
7098
+
7099
+ expect ( innerCompilationCount ) . toBe ( 1 ) ;
7100
+ } ) ;
7101
+ } ) ;
6895
7102
} ) ;
6896
7103
6897
7104
0 commit comments