diff options
Diffstat (limited to 'src/ng')
| -rw-r--r-- | src/ng/compile.js | 2 | ||||
| -rw-r--r-- | src/ng/directive/ngIf.js | 9 | ||||
| -rw-r--r-- | src/ng/directive/ngRepeat.js | 30 |
3 files changed, 27 insertions, 14 deletions
diff --git a/src/ng/compile.js b/src/ng/compile.js index fd8a8729..7d0bb008 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -931,7 +931,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { createBoundTranscludeFn(scope, childTranscludeFn || transcludeFn) ); } else { - nodeLinkFn(childLinkFn, childScope, node, undefined, boundTranscludeFn); + nodeLinkFn(childLinkFn, childScope, node, $rootElement, boundTranscludeFn); } } else if (childLinkFn) { childLinkFn(scope, node.childNodes, undefined, boundTranscludeFn); 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; } } diff --git a/src/ng/directive/ngRepeat.js b/src/ng/directive/ngRepeat.js index cd605bf3..86874a41 100644 --- a/src/ng/directive/ngRepeat.js +++ b/src/ng/directive/ngRepeat.js @@ -301,7 +301,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { } else if (nextBlockMap.hasOwnProperty(trackById)) { // restore lastBlockMap forEach(nextBlockOrder, function(block) { - if (block && block.startNode) lastBlockMap[block.id] = block; + if (block && block.scope) lastBlockMap[block.id] = block; }); // This is a duplicate and we need to throw an error throw ngRepeatMinErr('dupes', "Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: {0}, Duplicate key: {1}", @@ -318,7 +318,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { // lastBlockMap is our own object so we don't need to use special hasOwnPropertyFn if (lastBlockMap.hasOwnProperty(key)) { block = lastBlockMap[key]; - elementsToRemove = getBlockElements(block); + elementsToRemove = getBlockElements(block.clone); $animate.leave(elementsToRemove); forEach(elementsToRemove, function(element) { element[NG_REMOVED] = true; }); block.scope.$destroy(); @@ -330,9 +330,9 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { key = (collection === collectionKeys) ? index : collectionKeys[index]; value = collection[key]; block = nextBlockOrder[index]; - if (nextBlockOrder[index - 1]) previousNode = nextBlockOrder[index - 1].endNode; + if (nextBlockOrder[index - 1]) previousNode = getBlockEnd(nextBlockOrder[index - 1]); - if (block.startNode) { + if (block.scope) { // if we have already seen this object, then we need to reuse the // associated scope/element childScope = block.scope; @@ -342,11 +342,11 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { nextNode = nextNode.nextSibling; } while(nextNode && nextNode[NG_REMOVED]); - if (block.startNode != nextNode) { + if (getBlockStart(block) != nextNode) { // existing item which got moved - $animate.move(getBlockElements(block), null, jqLite(previousNode)); + $animate.move(getBlockElements(block.clone), null, jqLite(previousNode)); } - previousNode = block.endNode; + previousNode = getBlockEnd(block); } else { // new item which we don't know about childScope = $scope.$new(); @@ -362,14 +362,16 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { childScope.$odd = !(childScope.$even = (index&1) === 0); // jshint bitwise: true - if (!block.startNode) { + if (!block.scope) { $transclude(childScope, function(clone) { clone[clone.length++] = document.createComment(' end ngRepeat: ' + expression + ' '); $animate.enter(clone, null, jqLite(previousNode)); previousNode = clone; block.scope = childScope; - block.startNode = previousNode && previousNode.endNode ? previousNode.endNode : clone[0]; - block.endNode = clone[clone.length - 1]; + // 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.clone = clone; nextBlockMap[block.id] = block; }); } @@ -378,5 +380,13 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { }); } }; + + function getBlockStart(block) { + return block.clone[0]; + } + + function getBlockEnd(block) { + return block.clone[block.clone.length - 1]; + } }]; |
