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

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,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),
Expand Down
18 changes: 18 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2512,6 +2512,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(
Expand Down