Skip to content

Commit

Permalink
refactor(ngTransclude): use transclusion function passed in to link
Browse files Browse the repository at this point in the history
Since we now pass in the transclusion function directly to the link function, we no longer need
the old scheme whereby we saved the transclude function injected into the controller for later
use in during linking.

Additionally, this change may aid in correcting a memory leak of detached DOM nodes (see angular#6181
for details).

This commit removes the controller and simplifies ngTransclude.

Closes angular#5375
Closes angular#6181
  • Loading branch information
Daniel Tabuenca authored and Sebastien Armand - sa250111 committed Feb 19, 2014
1 parent f1ec06e commit b58a439
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/ng/directive/ngTransclude.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,16 @@
*
*/
var ngTranscludeDirective = ngDirective({
controller: ['$element', '$transclude', function($element, $transclude) {
link: function($scope, $element, $attrs, controller, $transclude) {
if (!$transclude) {
throw minErr('ngTransclude')('orphan',
'Illegal use of ngTransclude directive in the template! ' +
'No parent directive that requires a transclusion found. ' +
'Element: {0}',
startingTag($element));
'Illegal use of ngTransclude directive in the template! ' +
'No parent directive that requires a transclusion found. ' +
'Element: {0}',
startingTag($element));
}

// remember the transclusion fn but call it during linking so that we don't process transclusion before directives on
// the parent element even when the transclusion replaces the current element. (we can't use priority here because
// that applies only to compile fns and not controllers
this.$transclude = $transclude;
}],

link: function($scope, $element, $attrs, controller) {
controller.$transclude(function(clone) {

$transclude(function(clone) {
$element.empty();
$element.append(clone);
});
Expand Down

0 comments on commit b58a439

Please sign in to comment.