mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
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
This commit is contained in:
parent
c22ab5d2e2
commit
5ed721b9b5
2 changed files with 24 additions and 0 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue