diff --git a/src/ng/directive/booleanAttrs.js b/src/ng/directive/booleanAttrs.js index b00d021208a4..7c98abf31a26 100644 --- a/src/ng/directive/booleanAttrs.js +++ b/src/ng/directive/booleanAttrs.js @@ -380,8 +380,12 @@ forEach(['src', 'srcset', 'href'], function(attrName) { } attr.$observe(normalized, function(value) { - if (!value) - return; + if (!value) { + if (attrName === 'href') { + attr.$set(name, null); + } + return; + } attr.$set(name, value); diff --git a/test/ng/directive/booleanAttrsSpec.js b/test/ng/directive/booleanAttrsSpec.js index 6bcb57eeb2b8..2b4dc30c47b6 100644 --- a/test/ng/directive/booleanAttrsSpec.js +++ b/test/ng/directive/booleanAttrsSpec.js @@ -252,6 +252,23 @@ describe('ngHref', function() { expect(element.attr('href')).toEqual('http://server'); })); + it('should not set the href if ng-href is empty', inject(function($rootScope, $compile) { + $rootScope.url = null; + element = $compile('')($rootScope); + $rootScope.$digest(); + expect(element.attr('href')).toEqual(undefined); + })); + + it('should remove the href if ng-href changes to empty', inject(function($rootScope, $compile) { + $rootScope.url = 'http://www.google.com/'; + element = $compile('')($rootScope); + $rootScope.$digest(); + + $rootScope.url = null; + $rootScope.$digest(); + expect(element.attr('href')).toEqual(undefined); + })); + if (isDefined(window.SVGElement)) { describe('SVGAElement', function() { it('should interpolate the expression and bind to xlink:href', inject(function($compile, $rootScope) {