fix($compile): do not merge attrs that are the same for replace directives

If a directives specifies `replace:true` and the template of the directive contains
a root element with an attribute which already exists at the place
where the directive is used with the same value, don't duplicate the value.

Closes #7463
This commit is contained in:
Jeff Whelpley
2014-05-14 10:18:17 -04:00
committed by Tobias Bosch
parent c9ee20b64b
commit b635903ec4
2 changed files with 20 additions and 1 deletions
+1 -1
View File
@@ -1631,7 +1631,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]);
+19
View File
@@ -493,6 +493,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>',
@@ -597,6 +606,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>');