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

Commit 948c86c

Browse files
shahatabtford
authored andcommitted
fix(ngHref): remove attribute when empty value instead of ignoring
Closes #2755
1 parent cd63ff4 commit 948c86c

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/ng/directive/booleanAttrs.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,12 @@ forEach(['src', 'srcset', 'href'], function(attrName) {
380380
}
381381

382382
attr.$observe(normalized, function(value) {
383-
if (!value)
384-
return;
383+
if (!value) {
384+
if (attrName === 'href') {
385+
attr.$set(name, null);
386+
}
387+
return;
388+
}
385389

386390
attr.$set(name, value);
387391

test/ng/directive/booleanAttrsSpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,23 @@ describe('ngHref', function() {
252252
expect(element.attr('href')).toEqual('http://server');
253253
}));
254254

255+
it('should not set the href if ng-href is empty', inject(function($rootScope, $compile) {
256+
$rootScope.url = null;
257+
element = $compile('<a ng-href="{{url}}">')($rootScope);
258+
$rootScope.$digest();
259+
expect(element.attr('href')).toEqual(undefined);
260+
}));
261+
262+
it('should remove the href if ng-href changes to empty', inject(function($rootScope, $compile) {
263+
$rootScope.url = 'http://www.google.com/';
264+
element = $compile('<a ng-href="{{url}}">')($rootScope);
265+
$rootScope.$digest();
266+
267+
$rootScope.url = null;
268+
$rootScope.$digest();
269+
expect(element.attr('href')).toEqual(undefined);
270+
}));
271+
255272
if (isDefined(window.SVGElement)) {
256273
describe('SVGAElement', function() {
257274
it('should interpolate the expression and bind to xlink:href', inject(function($compile, $rootScope) {

0 commit comments

Comments
 (0)