diff options
Diffstat (limited to 'src/ng')
| -rw-r--r-- | src/ng/compile.js | 2 | ||||
| -rw-r--r-- | src/ng/directive/ngIf.js | 35 |
2 files changed, 28 insertions, 9 deletions
diff --git a/src/ng/compile.js b/src/ng/compile.js index 7754a8e6..af7d5e6b 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -1175,7 +1175,7 @@ function $CompileProvider($provide) { if (directiveValue = directive.transclude) { // Special case ngRepeat so that we don't complain about duplicate transclusion, ngRepeat // knows how to handle this on its own. - if (directiveName !== 'ngRepeat') { + if (directiveName !== 'ngRepeat' && directiveName !== 'ngIf') { assertNoDuplicate('transclusion', transcludeDirective, directive, $compileNode); transcludeDirective = directive; } diff --git a/src/ng/directive/ngIf.js b/src/ng/directive/ngIf.js index b2811ab4..662f3f32 100644 --- a/src/ng/directive/ngIf.js +++ b/src/ng/directive/ngIf.js @@ -86,20 +86,21 @@ var ngIfDirective = ['$animate', function($animate) { restrict: 'A', compile: function (element, attr, transclude) { return function ($scope, $element, $attr) { - var childElement, childScope; + var block = {}, childScope; $scope.$watch($attr.ngIf, function ngIfWatchAction(value) { - if (childElement) { - $animate.leave(childElement); - childElement = undefined; + if (block.startNode) { + $animate.leave(getBlockElements(block)); + block = {}; } - if (childScope) { - childScope.$destroy(); - childScope = undefined; + if (block.startNode) { + getBlockElements(block).$destroy(); + block = {}; } if (toBoolean(value)) { childScope = $scope.$new(); transclude(childScope, function (clone) { - childElement = clone; + block.startNode = clone[0]; + block.endNode = clone[clone.length++] = document.createComment(' end ngIf: ' + $attr.ngIf + ' '); $animate.enter(clone, $element.parent(), $element); }); } @@ -107,4 +108,22 @@ var ngIfDirective = ['$animate', function($animate) { }; } }; + + // TODO(bford): this helper was copypasta'd from ngRepeat + function getBlockElements(block) { + if (block.startNode === block.endNode) { + return jqLite(block.startNode); + } + + var element = block.startNode; + var elements = [element]; + + do { + element = element.nextSibling; + if (!element) break; + elements.push(element); + } while (element !== block.endNode); + + return jqLite(elements); + } }]; |
