aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ng/compile.js10
-rwxr-xr-xtest/ng/compileSpec.js41
2 files changed, 48 insertions, 3 deletions
diff --git a/src/ng/compile.js b/src/ng/compile.js
index 84432647..7754a8e6 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 0e394640..c6cba3a4 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('<div><div element-trans normal-dir></div></div>')($rootScope);
+ expect(log).toEqual([
+ 'controller:elementTrans',
+ 'controller:normalDir',
+ 'controller:normalDir',
+ 'controller:normalDir'
+ ]);
+ });
+ });
});