mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-03 22:44:00 +08:00
refactor(ngTransclude): use transclusion function passed in to link
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 #6181 for details). This commit removes the controller and simplifies ngTransclude. Closes #5375 Closes #6181
This commit is contained in:
committed by
Caitlin Potter
parent
ef4bf8c77c
commit
08793a690a
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user