@@ -6756,6 +6756,27 @@ describe('$compile', function() {
6756
6756
} ) ;
6757
6757
} ) ;
6758
6758
6759
+ it ( 'should only allow one element transclusion per element when replace directive is in the mix' , function ( ) {
6760
+ module ( function ( ) {
6761
+ directive ( 'template' , valueFn ( {
6762
+ template : '<p second></p>' ,
6763
+ replace : true
6764
+ } ) ) ;
6765
+ directive ( 'first' , valueFn ( {
6766
+ transclude : 'element' ,
6767
+ priority : 100
6768
+ } ) ) ;
6769
+ directive ( 'second' , valueFn ( {
6770
+ transclude : 'element'
6771
+ } ) ) ;
6772
+ } ) ;
6773
+ inject ( function ( $compile ) {
6774
+ expect ( function ( ) {
6775
+ $compile ( '<div template first></div>' ) ;
6776
+ } ) . 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 .+ / ) ;
6777
+ } ) ;
6778
+ } ) ;
6779
+
6759
6780
6760
6781
it ( 'should support transcluded element on root content' , function ( ) {
6761
6782
var comment ;
@@ -7052,6 +7073,192 @@ describe('$compile', function() {
7052
7073
} ) ;
7053
7074
7054
7075
} ) ;
7076
+
7077
+ it ( 'should lazily compile the contents of directives that are transcluded' , function ( ) {
7078
+ var innerCompilationCount = 0 , transclude ;
7079
+
7080
+ module ( function ( ) {
7081
+ directive ( 'trans' , valueFn ( {
7082
+ transclude : true ,
7083
+ controller : function ( $transclude ) {
7084
+ transclude = $transclude ;
7085
+ }
7086
+ } ) ) ;
7087
+
7088
+ directive ( 'inner' , valueFn ( {
7089
+ template : '<span>FooBar</span>' ,
7090
+ compile : function ( ) {
7091
+ innerCompilationCount += 1 ;
7092
+ }
7093
+ } ) ) ;
7094
+ } ) ;
7095
+
7096
+ inject ( function ( $compile , $rootScope ) {
7097
+ element = $compile ( '<trans><inner></inner></trans>' ) ( $rootScope ) ;
7098
+ expect ( innerCompilationCount ) . toBe ( 0 ) ;
7099
+ transclude ( function ( child ) { element . append ( child ) ; } ) ;
7100
+ expect ( innerCompilationCount ) . toBe ( 1 ) ;
7101
+ expect ( element . text ( ) ) . toBe ( 'FooBar' ) ;
7102
+ } ) ;
7103
+ } ) ;
7104
+
7105
+ it ( 'should lazily compile the contents of directives that are transcluded with a template' , function ( ) {
7106
+ var innerCompilationCount = 0 , transclude ;
7107
+
7108
+ module ( function ( ) {
7109
+ directive ( 'trans' , valueFn ( {
7110
+ transclude : true ,
7111
+ template : '<div>Baz</div>' ,
7112
+ controller : function ( $transclude ) {
7113
+ transclude = $transclude ;
7114
+ }
7115
+ } ) ) ;
7116
+
7117
+ directive ( 'inner' , valueFn ( {
7118
+ template : '<span>FooBar</span>' ,
7119
+ compile : function ( ) {
7120
+ innerCompilationCount += 1 ;
7121
+ }
7122
+ } ) ) ;
7123
+ } ) ;
7124
+
7125
+ inject ( function ( $compile , $rootScope ) {
7126
+ element = $compile ( '<trans><inner></inner></trans>' ) ( $rootScope ) ;
7127
+ expect ( innerCompilationCount ) . toBe ( 0 ) ;
7128
+ transclude ( function ( child ) { element . append ( child ) ; } ) ;
7129
+ expect ( innerCompilationCount ) . toBe ( 1 ) ;
7130
+ expect ( element . text ( ) ) . toBe ( 'BazFooBar' ) ;
7131
+ } ) ;
7132
+ } ) ;
7133
+
7134
+ it ( 'should lazily compile the contents of directives that are transcluded with a templateUrl' , function ( ) {
7135
+ var innerCompilationCount = 0 , transclude ;
7136
+
7137
+ module ( function ( ) {
7138
+ directive ( 'trans' , valueFn ( {
7139
+ transclude : true ,
7140
+ templateUrl : 'baz.html' ,
7141
+ controller : function ( $transclude ) {
7142
+ transclude = $transclude ;
7143
+ }
7144
+ } ) ) ;
7145
+
7146
+ directive ( 'inner' , valueFn ( {
7147
+ template : '<span>FooBar</span>' ,
7148
+ compile : function ( ) {
7149
+ innerCompilationCount += 1 ;
7150
+ }
7151
+ } ) ) ;
7152
+ } ) ;
7153
+
7154
+ inject ( function ( $compile , $rootScope , $httpBackend ) {
7155
+ $httpBackend . expectGET ( 'baz.html' ) . respond ( '<div>Baz</div>' ) ;
7156
+ element = $compile ( '<trans><inner></inner></trans>' ) ( $rootScope ) ;
7157
+ $httpBackend . flush ( ) ;
7158
+
7159
+ expect ( innerCompilationCount ) . toBe ( 0 ) ;
7160
+ transclude ( function ( child ) { element . append ( child ) ; } ) ;
7161
+ expect ( innerCompilationCount ) . toBe ( 1 ) ;
7162
+ expect ( element . text ( ) ) . toBe ( 'BazFooBar' ) ;
7163
+ } ) ;
7164
+ } ) ;
7165
+
7166
+ it ( 'should lazily compile the contents of directives that are transclude element' , function ( ) {
7167
+ var innerCompilationCount = 0 , transclude ;
7168
+
7169
+ module ( function ( ) {
7170
+ directive ( 'trans' , valueFn ( {
7171
+ transclude : 'element' ,
7172
+ controller : function ( $transclude ) {
7173
+ transclude = $transclude ;
7174
+ }
7175
+ } ) ) ;
7176
+
7177
+ directive ( 'inner' , valueFn ( {
7178
+ template : '<span>FooBar</span>' ,
7179
+ compile : function ( ) {
7180
+ innerCompilationCount += 1 ;
7181
+ }
7182
+ } ) ) ;
7183
+ } ) ;
7184
+
7185
+ inject ( function ( $compile , $rootScope ) {
7186
+ element = $compile ( '<div><trans><inner></inner></trans></div>' ) ( $rootScope ) ;
7187
+ expect ( innerCompilationCount ) . toBe ( 0 ) ;
7188
+ transclude ( function ( child ) { element . append ( child ) ; } ) ;
7189
+ expect ( innerCompilationCount ) . toBe ( 1 ) ;
7190
+ expect ( element . text ( ) ) . toBe ( 'FooBar' ) ;
7191
+ } ) ;
7192
+ } ) ;
7193
+
7194
+ it ( 'should lazily compile transcluded directives with ngIf on them' , function ( ) {
7195
+ var innerCompilationCount = 0 , outerCompilationCount = 0 , transclude ;
7196
+
7197
+ module ( function ( ) {
7198
+ directive ( 'outer' , valueFn ( {
7199
+ transclude : true ,
7200
+ compile : function ( ) {
7201
+ outerCompilationCount += 1 ;
7202
+ } ,
7203
+ controller : function ( $transclude ) {
7204
+ transclude = $transclude ;
7205
+ }
7206
+ } ) ) ;
7207
+
7208
+ directive ( 'inner' , valueFn ( {
7209
+ template : '<span>FooBar</span>' ,
7210
+ compile : function ( ) {
7211
+ innerCompilationCount += 1 ;
7212
+ }
7213
+ } ) ) ;
7214
+ } ) ;
7215
+
7216
+ inject ( function ( $compile , $rootScope ) {
7217
+ $rootScope . shouldCompile = false ;
7218
+
7219
+ element = $compile ( '<div><outer ng-if="shouldCompile"><inner></inner></outer></div>' ) ( $rootScope ) ;
7220
+ expect ( outerCompilationCount ) . toBe ( 0 ) ;
7221
+ expect ( innerCompilationCount ) . toBe ( 0 ) ;
7222
+ expect ( transclude ) . toBeUndefined ( ) ;
7223
+ $rootScope . $apply ( 'shouldCompile=true' ) ;
7224
+ expect ( outerCompilationCount ) . toBe ( 1 ) ;
7225
+ expect ( innerCompilationCount ) . toBe ( 0 ) ;
7226
+ expect ( transclude ) . toBeDefined ( ) ;
7227
+ transclude ( function ( child ) { element . append ( child ) ; } ) ;
7228
+ expect ( outerCompilationCount ) . toBe ( 1 ) ;
7229
+ expect ( innerCompilationCount ) . toBe ( 1 ) ;
7230
+ expect ( element . text ( ) ) . toBe ( 'FooBar' ) ;
7231
+ } ) ;
7232
+ } ) ;
7233
+
7234
+ it ( 'should eagerly compile multiple directives with transclusion and templateUrl/replace' , function ( ) {
7235
+ var innerCompilationCount = 0 ;
7236
+
7237
+ module ( function ( ) {
7238
+ directive ( 'outer' , valueFn ( {
7239
+ transclude : true
7240
+ } ) ) ;
7241
+
7242
+ directive ( 'outer' , valueFn ( {
7243
+ templateUrl : 'inner.html' ,
7244
+ replace : true
7245
+ } ) ) ;
7246
+
7247
+ directive ( 'inner' , valueFn ( {
7248
+ compile : function ( ) {
7249
+ innerCompilationCount += 1 ;
7250
+ }
7251
+ } ) ) ;
7252
+ } ) ;
7253
+
7254
+ inject ( function ( $compile , $rootScope , $httpBackend ) {
7255
+ $httpBackend . expectGET ( 'inner.html' ) . respond ( '<inner></inner>' ) ;
7256
+ element = $compile ( '<outer></outer>' ) ( $rootScope ) ;
7257
+ $httpBackend . flush ( ) ;
7258
+
7259
+ expect ( innerCompilationCount ) . toBe ( 1 ) ;
7260
+ } ) ;
7261
+ } ) ;
7055
7262
} ) ;
7056
7263
7057
7264
0 commit comments