diff --git a/src/ng/compile.js b/src/ng/compile.js index 4256adcaabc7..941c54701244 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -859,8 +859,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { } } - if (cloneConnectFn) cloneConnectFn($linkNode, scope); - if (compositeLinkFn) compositeLinkFn(scope, $linkNode, $linkNode); + var overrides = {}; + if (cloneConnectFn) { + angular.extend(overrides, cloneConnectFn($linkNode, scope)); + } + if (compositeLinkFn && !overrides.alreadyLinked) { + compositeLinkFn(scope, $linkNode, $linkNode); + } return $linkNode; }; } diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 4e6d85c7dc1d..9934c3abb390 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -3898,6 +3898,28 @@ describe('$compile', function() { }); + it('should skip automatic linking if the user indicates they want to take care of it themselves', function() { + module(function() { + directive('transclude', valueFn({ + transclude: 'content', + link: function(scope, element, attr, ctrl, $transclude) { + $transclude(function(clone) { + $compile(clone)(scope); + return { + alreadyLinked: true + }; + }); + } + })); + }); + inject(function($compile) { + $rootScope.list = ['Initial']; + element = $compile('
')($rootScope); + $rootScope.$apply(); + expect($rootScope.list).toEqual(['Initial', 'Compiled']); + }); + }); + it('should expose the directive controller to transcluded children', function() { var capturedChildCtrl; module(function() {