This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +48
-3
lines changed
2 files changed +48
-3
lines changed Original file line number Diff line number Diff line change @@ -1191,9 +1191,13 @@ function $CompileProvider($provide) {
1191
1191
1192
1192
childTranscludeFn = compile ( $template , transcludeFn , terminalPriority ,
1193
1193
replaceDirective && replaceDirective . name , {
1194
- controllerDirectives : controllerDirectives ,
1195
- newIsolateScopeDirective : newIsolateScopeDirective ,
1196
- templateDirective : templateDirective ,
1194
+ // Don't pass in:
1195
+ // - controllerDirectives - otherwise we'll create duplicates controllers
1196
+ // - newIsolateScopeDirective or templateDirective - combining templates with
1197
+ // element transclusion doesn't make sense.
1198
+ //
1199
+ // We need only transcludeDirective so that we prevent putting transclusion
1200
+ // on the same element more than once.
1197
1201
transcludeDirective : transcludeDirective
1198
1202
} ) ;
1199
1203
} else {
Original file line number Diff line number Diff line change @@ -3179,6 +3179,47 @@ describe('$compile', function() {
3179
3179
expect ( log ) . toEqual ( 'compile:elementTrans; compile:regularTrans; regular' ) ;
3180
3180
} ) ;
3181
3181
} ) ;
3182
+
3183
+
3184
+ it ( 'should instantiate high priority controllers only once, but low priority ones each time we transclude' ,
3185
+ function ( ) {
3186
+ module ( function ( ) {
3187
+ directive ( 'elementTrans' , function ( log ) {
3188
+ return {
3189
+ transclude : 'element' ,
3190
+ priority : 50 ,
3191
+ controller : function ( $transclude , $element ) {
3192
+ log ( 'controller:elementTrans' ) ;
3193
+ $transclude ( function ( clone ) {
3194
+ $element . after ( clone ) ;
3195
+ } ) ;
3196
+ $transclude ( function ( clone ) {
3197
+ $element . after ( clone ) ;
3198
+ } ) ;
3199
+ $transclude ( function ( clone ) {
3200
+ $element . after ( clone ) ;
3201
+ } ) ;
3202
+ }
3203
+ } ;
3204
+ } ) ;
3205
+ directive ( 'normalDir' , function ( log ) {
3206
+ return {
3207
+ controller : function ( ) {
3208
+ log ( 'controller:normalDir' ) ;
3209
+ }
3210
+ } ;
3211
+ } ) ;
3212
+ } ) ;
3213
+ inject ( function ( $compile , $rootScope , log ) {
3214
+ element = $compile ( '<div><div element-trans normal-dir></div></div>' ) ( $rootScope ) ;
3215
+ expect ( log ) . toEqual ( [
3216
+ 'controller:elementTrans' ,
3217
+ 'controller:normalDir' ,
3218
+ 'controller:normalDir' ,
3219
+ 'controller:normalDir'
3220
+ ] ) ;
3221
+ } ) ;
3222
+ } ) ;
3182
3223
} ) ;
3183
3224
3184
3225
You can’t perform that action at this time.
0 commit comments