Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat(compile): post-t'clusion linking now optional #7271

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
Expand Down
22 changes: 22 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div transclude><div ng-init="list.push(\'Compiled\')"></div></div>')($rootScope);
$rootScope.$apply();
expect($rootScope.list).toEqual(['Initial', 'Compiled']);
});
});

it('should expose the directive controller to transcluded children', function() {
var capturedChildCtrl;
module(function() {
Expand Down