Skip to content

Commit 7f976fc

Browse files
committed
fix($compile): don't add leading white-space in attributes for a specific merge case
If the replaced element had an attribute with an empty ("") value, merging the attribute from the template would result in a leading white-space.
1 parent 41988de commit 7f976fc

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/ng/compile.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2753,7 +2753,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
27532753
forEach(dst, function(value, key) {
27542754
if (key.charAt(0) !== '$') {
27552755
if (src[key] && src[key] !== value) {
2756-
value += (key === 'style' ? ';' : ' ') + src[key];
2756+
if (value.length) {
2757+
value += (key === 'style' ? ';' : ' ') + src[key];
2758+
} else {
2759+
value = src[key];
2760+
}
27572761
}
27582762
dst.$set(key, value, true, srcAttr[key]);
27592763
}

test/ng/compileSpec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,18 @@ describe('$compile', function() {
980980
}));
981981

982982

983+
it('should not add white-space when merging an attribute that is "" in the replaced element',
984+
inject(function($compile, $rootScope) {
985+
element = $compile(
986+
'<div><div replace class=""></div><div>')($rootScope);
987+
var div = element.find('div');
988+
expect(div.hasClass('log')).toBe(true);
989+
expect(div.attr('class')).toBe('log');
990+
console.log('el', div);
991+
})
992+
);
993+
994+
983995
it('should prevent multiple templates per element', inject(function($compile) {
984996
try {
985997
$compile('<div><span replace class="replace"></span></div>');

0 commit comments

Comments
 (0)