aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaitlin Potter2014-01-03 11:50:53 -0500
committerCaitlin Potter2014-01-31 12:45:35 -0500
commit5ed721b9b5e95ae08450e1ae9d5202e7f3f79295 (patch)
tree51f4b0f3dcc3ed684e5f5c91edf0de2569ebedc0
parentc22ab5d2e28605462ba77f6c02e99efdd24338a3 (diff)
downloadangular.js-5ed721b9b5e95ae08450e1ae9d5202e7f3f79295.tar.bz2
fix($compile): retain CSS classes added in cloneAttachFn on asynchronous directives
Previously, classes added to asynchronous directive elements during the clone attach function would not persist after the node is merged with the template, prior to linking. This change corrects this behaviour and brings it in line with synchronous directives. Closes #5439 Closes #5617
-rw-r--r--src/ng/compile.js4
-rwxr-xr-xtest/ng/compileSpec.js20
2 files changed, 24 insertions, 0 deletions
diff --git a/src/ng/compile.js b/src/ng/compile.js
index 193dff7a..36c23086 100644
--- a/src/ng/compile.js
+++ b/src/ng/compile.js
@@ -1711,9 +1711,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
linkNode = $compileNode[0];
if (beforeTemplateLinkNode !== beforeTemplateCompileNode) {
+ var oldClasses = beforeTemplateLinkNode.className;
// it was cloned therefore we have to clone as well.
linkNode = jqLiteClone(compileNode);
replaceWith(linkRootElement, jqLite(beforeTemplateLinkNode), linkNode);
+
+ // Copy in CSS classes from original node
+ safeAddClass(jqLite(linkNode), oldClasses);
}
if (afterTemplateNodeLinkFn.transclude) {
childBoundTranscludeFn = createBoundTranscludeFn(scope, afterTemplateNodeLinkFn.transclude);
diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js
index c37461fc..557fb85c 100755
--- a/test/ng/compileSpec.js
+++ b/test/ng/compileSpec.js
@@ -1128,6 +1128,26 @@ describe('$compile', function() {
});
+ it('should copy classes from pre-template node into linked element', function() {
+ module(function() {
+ directive('test', valueFn({
+ templateUrl: 'test.html',
+ replace: true
+ }));
+ });
+ inject(function($compile, $templateCache, $rootScope) {
+ var child;
+ $templateCache.put('test.html', '<p class="template-class">Hello</p>');
+ element = $compile('<div test></div>')($rootScope, function(node) {
+ node.addClass('clonefn-class');
+ });
+ $rootScope.$digest();
+ expect(element).toHaveClass('template-class');
+ expect(element).toHaveClass('clonefn-class');
+ });
+ });
+
+
describe('delay compile / linking functions until after template is resolved', function(){
var template;
beforeEach(module(function() {