Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Do not merge attributes that are the same #7463

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
// reapply the old attributes to the new element
forEach(dst, function(value, key) {
if (key.charAt(0) != '$') {
if (src[key]) {
if (src[key] && src[key] !== value) {
value += (key === 'style' ? ';' : ' ') + src[key];
}
dst.$set(key, value, true, srcAttr[key]);
Expand Down
19 changes: 19 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,15 @@ describe('$compile', function() {
expect(element).toBe(attr.$$element);
}
}));
directive('nomerge', valueFn({
restrict: 'CAM',
replace: true,
template: '<div class="log" id="myid" high-log>No Merge!</div>',
compile: function(element, attr) {
attr.$set('compiled', 'COMPILED');
expect(element).toBe(attr.$$element);
}
}));
directive('append', valueFn({
restrict: 'CAM',
template: '<div class="log" style="width: 10px" high-log>Append!</div>',
Expand Down Expand Up @@ -596,6 +605,16 @@ describe('$compile', function() {
expect(div.attr('high-log')).toEqual('');
}));

it('should not merge attributes if they are the same', inject(function($compile, $rootScope) {
element = $compile(
'<div><div nomerge class="medium-log" id="myid"></div><div>')
($rootScope);
var div = element.find('div');
expect(div.hasClass('medium-log')).toBe(true);
expect(div.hasClass('log')).toBe(true);
expect(div.attr('id')).toEqual('myid');
}));

it('should prevent multiple templates per element', inject(function($compile) {
try {
$compile('<div><span replace class="replace"></span></div>');
Expand Down