diff options
| author | Igor Minar | 2012-05-03 21:49:06 -0700 | 
|---|---|---|
| committer | Igor Minar | 2012-05-03 23:40:43 -0700 | 
| commit | b431ee38509724ba9098a7be7a8d6c5dcded4fe9 (patch) | |
| tree | 5f0dc9efb902033be927c0acfaf38f67b9c740f7 /src/ng/compile.js | |
| parent | a44d3dcd6a31f21de957855c732a28c881372549 (diff) | |
| download | angular.js-b431ee38509724ba9098a7be7a8d6c5dcded4fe9.tar.bz2 | |
fix($compile): fix replaceWith
the old implementation didn't reattach jquery/jqlite data which caused
things like  to be lost
I tried various implementations but it appears that by reattaching the data
to the new node by copying the expando property is the most reliable of all.
Diffstat (limited to 'src/ng/compile.js')
| -rw-r--r-- | src/ng/compile.js | 18 | 
1 files changed, 6 insertions, 12 deletions
| diff --git a/src/ng/compile.js b/src/ng/compile.js index 5db7b671..00628365 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -867,22 +867,12 @@ function $CompileProvider($provide) {                  linkRootElement = linkQueue.pop(),                  origLinkNode = linkQueue.pop(),                  scope = linkQueue.pop(), -                linkNode = compileNode, -                $origLinkNode = jqLite(origLinkNode); +                linkNode = compileNode;              if (origLinkNode !== origCompileNode) {                // it was cloned therefore we have to clone as well.                linkNode = JQLiteClone(compileNode); -              replaceWith(linkRootElement, $origLinkNode, linkNode); -            } - -            if (replace) { -              if ($origLinkNode.data('$scope')) { -                // if the original element before replacement had a new scope, the replacement should -                // get it as well -                jqLite(linkNode).data('$scope', scope); -              } -              dealoc($origLinkNode); +              replaceWith(linkRootElement, jqLite(origLinkNode), linkNode);              }              afterTemplateNodeLinkFn(function() { @@ -992,12 +982,16 @@ function $CompileProvider($provide) {          for(i = 0, ii = $rootElement.length; i < ii; i++) {            if ($rootElement[i] == oldNode) {              $rootElement[i] = newNode; +            break;            }          }        } +        if (parent) {          parent.replaceChild(newNode, oldNode);        } + +      newNode[jqLite.expando] = oldNode[jqLite.expando];        $element[0] = newNode;      }    }]; | 
