diff --git a/src/ng/compile.js b/src/ng/compile.js index d97aeaf6e557..fea91aa6fa3f 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -383,7 +383,10 @@ function $CompileProvider($provide) { if (writeAttr !== false) { if (value === null || value === undefined) { this.$$element.removeAttr(attrName); - } else { + } else if (value !== this.$$element.attr(attrName)) { + // Set new value only if it is not already there, avoiding + // issues with IE, where certain attributes cannot be set + // on in-document elements, e.g. 'type' on this.$$element.attr(attrName, value); } } @@ -1130,8 +1133,9 @@ function $CompileProvider($provide) { // reapply the old attributes to the new element forEach(dst, function(value, key) { if (key.charAt(0) != '$') { - if (src[key]) { - value += (key === 'style' ? ';' : ' ') + src[key]; + var srcVal = src[key]; + if (srcVal && srcVal !== value) { + value += (key === 'style' ? ';' : ' ') + srcVal; } dst.$set(key, value, true, srcAttr[key]); } diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index d26438783d70..7267d9638ca1 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -489,6 +489,14 @@ describe('$compile', function() { expect(element).toBe(attr.$$element); } })); + directive('replaceWithArbitraryAttribute', valueFn({ + replace: true, + template: '