fix($compile): Handle the removal of an interpolated attribute

Handle the removal of an interpolated attribute before the
attribute interpolating directive is linked

Closes #9236
Closes #9240
This commit is contained in:
Lucas Galfaso
2014-09-24 08:05:57 +02:00
committed by Igor Minar
parent e843ae7a4c
commit a75546afdf
2 changed files with 23 additions and 0 deletions

View File

@@ -2291,6 +2291,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
"ng- versions (such as ng-click instead of onclick) instead.");
}
// If the attribute was removed, then we are done
if (!attr[name]) {
return;
}
// we need to interpolate again, in case the attribute value has been updated
// (e.g. by another directive's compile function)
interpolateFn = $interpolate(attr[name], true, getTrustedContext(node, name),

View File

@@ -2547,6 +2547,24 @@ describe('$compile', function() {
});
});
it('should allow the attribute to be removed before the attribute interpolation', function () {
module(function() {
directive('removeAttr', function () {
return {
restrict:'A',
compile: function (tElement, tAttr) {
tAttr.$set('removeAttr', null);
}
};
});
});
inject(function ($rootScope, $compile) {
expect(function () {
element = $compile('<div remove-attr="{{ toBeRemoved }}"></div>')($rootScope);
}).not.toThrow();
expect(element.attr('remove-attr')).toBeUndefined();
});
});
describe('SCE values', function() {
it('should resolve compile and link both attribute and text bindings', inject(