From 96faecaecfbbeba095983975e21bfd0326bc5ec2 Mon Sep 17 00:00:00 2001 From: Lucas Galfaso Date: Wed, 24 Sep 2014 08:05:57 +0200 Subject: [PATCH] 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 --- src/ng/compile.js | 5 +++++ test/ng/compileSpec.js | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/ng/compile.js b/src/ng/compile.js index f75cb7393f11..713b0d224d5c 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -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), diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 2a0d84d04150..3eb8c1a4a30b 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -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('
')($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(