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 jeffbcross committed Aug 13, 2014
1 parent cb18343 commit ed56872
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/booleanAttrs.js
Expand Up @@ -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);

Expand Down
17 changes: 17 additions & 0 deletions test/ng/directive/booleanAttrsSpec.js
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}}"></a>')($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}}"></a>')($rootScope);
$rootScope.$digest();

This comment has been minimized.

Copy link
@IgorMinar

IgorMinar Aug 16, 2014

Contributor

this test would have been more solid if you made an assertion here that the attribute is set at this point


$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 ed56872

Please sign in to comment.