Permalink
Browse files

fix($compile): correctly merge class attr for replace directives

Merging of interpolated class attribute from directive template with replace:true works

Closes #1006
  • Loading branch information...
maxmart authored and IgorMinar committed Jun 6, 2012
1 parent 10f80d7 commit fb99b539b4d851773b43f1564f7032adb157c0db
Showing with 19 additions and 0 deletions.
  1. +3 −0 src/ng/compile.js
  2. +16 −0 test/ng/compileSpec.js
View
@@ -865,6 +865,7 @@ function $CompileProvider($provide) {
var srcAttr = src.$attr,
dstAttr = dst.$attr,
$element = dst.$$element;
// reapply the old attributes to the new element
forEach(dst, function(value, key) {
if (key.charAt(0) != '$') {
@@ -874,10 +875,12 @@ function $CompileProvider($provide) {
dst.$set(key, value, true, srcAttr[key]);
}
});
// copy the new attributes on the old attrs object
forEach(src, function(value, key) {
if (key == 'class') {
safeAddClass($element, value);
dst['class'] = (dst['class'] ? dst['class'] + ' ' : '') + value;
} else if (key == 'style') {
$element.attr('style', $element.attr('style') + ';' + value);
} else if (key.charAt(0) != '$' && !dst.hasOwnProperty(key)) {
View
@@ -388,6 +388,14 @@ describe('$compile', function() {
expect(element).toBe(attr.$$element);
}
}));
directive('replaceWithInterpolatedClass', valueFn({
replace: true,
template: '<div class="class_{{1+1}}">Replace with interpolated class!</div>',
compile: function(element, attr) {
attr.$set('compiled', 'COMPILED');
expect(element).toBe(attr.$$element);
}
}));
}));
@@ -466,6 +474,14 @@ describe('$compile', function() {
}));
it('should handle interpolated css from replacing directive', inject(
function($compile, $rootScope) {
element = $compile('<div replace-with-interpolated-class></div>')($rootScope);
$rootScope.$digest();
expect(element).toHaveClass('class_2');
}));
it('should merge interpolated css class', inject(function($compile, $rootScope) {
element = $compile('<div class="one {{cls}} three" replace></div>')($rootScope);

0 comments on commit fb99b53

Please sign in to comment.