Skip to content

Commit 96faeca

Browse files
committedSep 24, 2014
fix($compile): Handle the removal of an interpolated attribute
Handle the removal of an interpolated attribute before the attribute interpolating directive is linked Closes angular#9236
1 parent de38899 commit 96faeca

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
@@ -2136,6 +2136,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
21362136
"ng- versions (such as ng-click instead of onclick) instead.");
21372137
}
21382138

2139+
// If the attribute was removed, then we are done
2140+
if (!attr[name]) {
2141+
return;
2142+
}
2143+
21392144
// we need to interpolate again, in case the attribute value has been updated
21402145
// (e.g. by another directive's compile function)
21412146
interpolateFn = $interpolate(attr[name], true, getTrustedContext(node, name),

‎test/ng/compileSpec.js

+18
Original file line numberDiff line numberDiff line change
@@ -2512,6 +2512,24 @@ describe('$compile', function() {
25122512
});
25132513
});
25142514

2515+
it('should allow the attribute to be removed before the attribute interpolation', function () {
2516+
module(function() {
2517+
directive('removeAttr', function () {
2518+
return {
2519+
restrict:'A',
2520+
compile: function (tElement, tAttr) {
2521+
tAttr.$set('removeAttr', null);
2522+
}
2523+
};
2524+
});
2525+
});
2526+
inject(function ($rootScope, $compile) {
2527+
expect(function () {
2528+
element = $compile('<div remove-attr="{{ toBeRemoved }}"></div>')($rootScope);
2529+
}).not.toThrow();
2530+
expect(element.attr('remove-attr')).toBeUndefined();
2531+
});
2532+
});
25152533

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

0 commit comments

Comments
 (0)
Please sign in to comment.