diff options
Diffstat (limited to 'src/ng/directive/ngIf.js')
| -rw-r--r-- | src/ng/directive/ngIf.js | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/ng/directive/ngIf.js b/src/ng/directive/ngIf.js index 35c122ad..78547f47 100644 --- a/src/ng/directive/ngIf.js +++ b/src/ng/directive/ngIf.js @@ -87,23 +87,31 @@ var ngIfDirective = ['$animate', function($animate) { $$tlb: true, compile: function (element, attr, transclude) { return function ($scope, $element, $attr) { - var block = {}, childScope; + var block, childScope; $scope.$watch($attr.ngIf, function ngIfWatchAction(value) { - if (block.startNode) { - $animate.leave(getBlockElements(block)); - block = {}; - } - if (block.startNode) { - getBlockElements(block).$destroy(); - block = {}; - } + if (toBoolean(value)) { + childScope = $scope.$new(); transclude(childScope, function (clone) { - block.startNode = clone[0]; - block.endNode = clone[clone.length++] = document.createComment(' end ngIf: ' + $attr.ngIf + ' '); + block = { + startNode: clone[0], + endNode: clone[clone.length++] = document.createComment(' end ngIf: ' + $attr.ngIf + ' ') + }; $animate.enter(clone, $element.parent(), $element); }); + + } else { + + if (childScope) { + childScope.$destroy(); + childScope = null; + } + + if (block) { + $animate.leave(getBlockElements(block)); + block = null; + } } }); }; |
