mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-23 11:37:38 +08:00
fix(ngHref): remove attribute when empty value instead of ignoring
Closes #2755
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user