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

Commit

Permalink
fix(ngHref): remove attribute when empty value instead of ignoring
Browse files Browse the repository at this point in the history
Closes #2755
  • Loading branch information
shahata authored and btford committed Jul 23, 2014
1 parent 1a2ed70 commit 469ea33
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ng/directive/attrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,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);

Expand Down
17 changes: 17 additions & 0 deletions test/ng/directive/booleanAttrsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<a ng-href="{{url}}">')($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('<a ng-href="{{url}}">')($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) {
Expand Down

0 comments on commit 469ea33

Please sign in to comment.