fix($compile): don't touch static element attributes

Compiler should not reassign values to element attributes if its not neccessary due
to interpolation or special attribute magic (ng-src -> src)

This resolves several issues on IE caused by reassigning script.src attribute which
caused all of the scripts to be reloaded.
This commit is contained in:
Igor Minar 2012-03-20 00:00:09 -07:00
parent 15213ec212
commit 9cb2195e61

View file

@ -861,16 +861,21 @@ function $CompileProvider($provide) {
function addAttrInterpolateDirective(node, directives, value, name) {
var interpolateFn = $interpolate(value, true);
if (SIDE_EFFECT_ATTRS[name]) {
name = SIDE_EFFECT_ATTRS[name];
if (isBooleanAttr(node, name)) {
value = true;
}
} else if (!interpolateFn) {
// we are not a side-effect attr, and we have no side-effects -> ignore
var interpolateFn = $interpolate(value, true),
realName = SIDE_EFFECT_ATTRS[name],
specialAttrDir = (realName && (realName !== name));
realName = realName || name;
if (specialAttrDir && isBooleanAttr(node, name)) {
value = true;
}
// no interpolation found and we are not a side-effect attr -> ignore
if (!interpolateFn && !specialAttrDir) {
return;
}
directives.push({
priority: 100,
compile: function(element, attr) {
@ -884,14 +889,14 @@ function $CompileProvider($provide) {
// we define observers array only for interpolated attrs
// and ignore observers for non interpolated attrs to save some memory
attr.$observers[name] = [];
attr[name] = undefined;
attr.$observers[realName] = [];
attr[realName] = undefined;
scope.$watch(interpolateFn, function(value) {
attr.$set(name, value);
attr.$set(realName, value);
});
};
} else {
attr.$set(name, value);
attr.$set(realName, value);
}
}
});