Skip to content

Commit

Permalink
Issues angular#1941 - This fixes an issue that sometimes breaks $obse…
Browse files Browse the repository at this point in the history
…rve when using a templateUrl for a directive. http://plnkr.co/edit/xJNt918gEpuXR026VuZB?p=preview illustrates the issue that was fixed
  • Loading branch information
Scott Lundberg committed Jul 31, 2013
1 parent 24a4450 commit 970345e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,10 +869,10 @@ function $CompileProvider($provide) {
}


function nodeLinkFn(childLinkFn, scope, linkNode, $rootElement, boundTranscludeFn) {
function nodeLinkFn(childLinkFn, scope, linkNode, $rootElement, boundTranscludeFn, forceSameAttrs) {
var attrs, $element, i, ii, linkFn, controller;

if (compileNode === linkNode) {
if (forceSameAttrs || compileNode === linkNode) {
attrs = templateAttrs;
} else {
attrs = shallowCopy(templateAttrs, new Attributes(jqLite(linkNode), templateAttrs.$attr));
Expand Down Expand Up @@ -1151,9 +1151,14 @@ function $CompileProvider($provide) {
replaceWith(linkRootElement, jqLite(beforeTemplateLinkNode), linkNode);
}

// When a node is cloned above this would cause the link functions to create a new attrs object,
// but by setting their last argument to "true" below we force them to keep the same attrs object.
// Without this flag the $$observers is put on the afterTemplateNodeLinkFn version of attrs and the $set
// is called on the beforeTemplateNodeLinkFn version of the attrs whenever we
// make a cloned linkNode above, thus breaking $observe. See github issue #1941
afterTemplateNodeLinkFn(function() {
beforeTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, linkNode, $rootElement, controller);
}, scope, linkNode, $rootElement, controller);
beforeTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, linkNode, $rootElement, controller, true);
}, scope, linkNode, $rootElement, controller, true);
}
linkQueue = null;
}).
Expand All @@ -1169,8 +1174,8 @@ function $CompileProvider($provide) {
linkQueue.push(controller);
} else {
afterTemplateNodeLinkFn(function() {
beforeTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, node, rootElement, controller);
}, scope, node, rootElement, controller);
beforeTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, node, rootElement, controller, true);
}, scope, node, rootElement, controller, true);
}
};
}
Expand Down

0 comments on commit 970345e

Please sign in to comment.