From b0972a2e75909e41dbac6e4413ada7df2d51df3a Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Tue, 26 Nov 2013 19:55:02 -0800 Subject: fix($compile): update cloned elements if the template arrives after the cloning If an element has a directive whose content is loaded using `templateUrl`, and the element is cloned using a linking function before the template arrives, the clone needs to be updated as well. This also updates `ngIf` and `ngRepeat` to keep the connection to the clone of a tranclude function, so that they know about the changes a directive with `templateUrl` does to the element in the future. Fixes to #4930. --- src/ng/directive/ngIf.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/ng/directive/ngIf.js') diff --git a/src/ng/directive/ngIf.js b/src/ng/directive/ngIf.js index dcb3825d..a05d30d0 100644 --- a/src/ng/directive/ngIf.js +++ b/src/ng/directive/ngIf.js @@ -94,9 +94,12 @@ var ngIfDirective = ['$animate', function($animate) { if (!childScope) { childScope = $scope.$new(); $transclude(childScope, function (clone) { + clone[clone.length++] = document.createComment(' end ngIf: ' + $attr.ngIf + ' '); + // Note: We only need the first/last node of the cloned nodes. + // However, we need to keep the reference to the jqlite wrapper as it might be changed later + // by a directive with templateUrl when it's template arrives. block = { - startNode: clone[0], - endNode: clone[clone.length++] = document.createComment(' end ngIf: ' + $attr.ngIf + ' ') + clone: clone }; $animate.enter(clone, $element.parent(), $element); }); @@ -109,7 +112,7 @@ var ngIfDirective = ['$animate', function($animate) { } if (block) { - $animate.leave(getBlockElements(block)); + $animate.leave(getBlockElements(block.clone)); block = null; } } -- cgit v1.2.3