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

fix(ngHref): allow setting href to empty string #6983

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ng/directive/booleanAttrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ forEach(['src', 'srcset', 'href'], function(attrName) {
}

attr.$observe(normalized, function(value) {
if (!value)
if (!value && attrName === 'src')
return;

attr.$set(name, value);
Expand Down
12 changes: 12 additions & 0 deletions test/ng/directive/booleanAttrsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,18 @@ describe('ngHref', function() {
}));


it('should remote href value when interpolated value is empty', inject(function($compile, $rootScope) {
element = $compile('<div ng-href="{{id}}"></div>')($rootScope);
$rootScope.$digest();
expect(element.attr('href')).toEqual('');

$rootScope.$apply(function() {
$rootScope.id = 1;
});
expect(element.attr('href')).toEqual('1');
}));


it('should bind href even if no interpolation', inject(function($rootScope, $compile) {
element = $compile('<a ng-href="http://server"></a>')($rootScope)
$rootScope.$digest();
Expand Down