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

Commit a75546a

Browse files
lgalfasoIgorMinar
authored andcommitted
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
1 parent e843ae7 commit a75546a

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/ng/compile.js

+5
Original file line numberDiff line numberDiff line change
@@ -2291,6 +2291,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
22912291
"ng- versions (such as ng-click instead of onclick) instead.");
22922292
}
22932293

2294+
// If the attribute was removed, then we are done
2295+
if (!attr[name]) {
2296+
return;
2297+
}
2298+
22942299
// we need to interpolate again, in case the attribute value has been updated
22952300
// (e.g. by another directive's compile function)
22962301
interpolateFn = $interpolate(attr[name], true, getTrustedContext(node, name),

test/ng/compileSpec.js

+18
Original file line numberDiff line numberDiff line change
@@ -2547,6 +2547,24 @@ describe('$compile', function() {
25472547
});
25482548
});
25492549

2550+
it('should allow the attribute to be removed before the attribute interpolation', function () {
2551+
module(function() {
2552+
directive('removeAttr', function () {
2553+
return {
2554+
restrict:'A',
2555+
compile: function (tElement, tAttr) {
2556+
tAttr.$set('removeAttr', null);
2557+
}
2558+
};
2559+
});
2560+
});
2561+
inject(function ($rootScope, $compile) {
2562+
expect(function () {
2563+
element = $compile('<div remove-attr="{{ toBeRemoved }}"></div>')($rootScope);
2564+
}).not.toThrow();
2565+
expect(element.attr('remove-attr')).toBeUndefined();
2566+
});
2567+
});
25502568

25512569
describe('SCE values', function() {
25522570
it('should resolve compile and link both attribute and text bindings', inject(

0 commit comments

Comments
 (0)