diff --git a/src/ng/compile.js b/src/ng/compile.js index 84432647fe01..7754a8e6d69f 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -1191,9 +1191,13 @@ function $CompileProvider($provide) { childTranscludeFn = compile($template, transcludeFn, terminalPriority, replaceDirective && replaceDirective.name, { - controllerDirectives: controllerDirectives, - newIsolateScopeDirective: newIsolateScopeDirective, - templateDirective: templateDirective, + // Don't pass in: + // - controllerDirectives - otherwise we'll create duplicates controllers + // - newIsolateScopeDirective or templateDirective - combining templates with + // element transclusion doesn't make sense. + // + // We need only transcludeDirective so that we prevent putting transclusion + // on the same element more than once. transcludeDirective: transcludeDirective }); } else { diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 0e3946406b2c..c6cba3a42fb1 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -3179,6 +3179,47 @@ describe('$compile', function() { expect(log).toEqual('compile:elementTrans; compile:regularTrans; regular'); }); }); + + + it('should instantiate high priority controllers only once, but low priority ones each time we transclude', + function() { + module(function() { + directive('elementTrans', function(log) { + return { + transclude: 'element', + priority: 50, + controller: function($transclude, $element) { + log('controller:elementTrans'); + $transclude(function(clone) { + $element.after(clone); + }); + $transclude(function(clone) { + $element.after(clone); + }); + $transclude(function(clone) { + $element.after(clone); + }); + } + }; + }); + directive('normalDir', function(log) { + return { + controller: function() { + log('controller:normalDir'); + } + }; + }); + }); + inject(function($compile, $rootScope, log) { + element = $compile('