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

Commit 2f5dba4

Browse files
committed
fix(ng-href): copy even if no binding
Closes# 850 fixed an issue where ng-href would not copy its content into href if it did not contain binding.
1 parent 7e86eac commit 2f5dba4

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/ng/directive/booleanAttrDirs.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,21 @@ forEach(['src', 'href'], function(attrName) {
302302
var normalized = directiveNormalize('ng-' + attrName);
303303
ngAttributeAliasDirectives[normalized] = function() {
304304
return {
305-
priority: 100,
305+
priority: 99, // it needs to run after the attributes are interpolated
306306
compile: function(tpl, attr) {
307307
return function(scope, element, attr) {
308-
attr.$$observers[attrName] = [];
309-
attr.$observe(normalized, function(value) {
308+
var value = attr[normalized];
309+
if (value == undefined) {
310+
// undefined value means that the directive is being interpolated
311+
// so just register observer
312+
attr.$$observers[attrName] = [];
313+
attr.$observe(normalized, function(value) {
314+
attr.$set(attrName, value);
315+
});
316+
} else {
317+
// value present means that no interpolation, so copy to native attribute.
310318
attr.$set(attrName, value);
311-
});
319+
}
312320
};
313321
}
314322
};

test/ng/directive/booleanAttrDirSpecs.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ describe('boolean attr directives', function() {
1010

1111
it('should bind href', inject(function($rootScope, $compile) {
1212
element = $compile('<a ng-href="{{url}}"></a>')($rootScope)
13-
$rootScope.url = 'http://server'
13+
$rootScope.url = 'http://server';
14+
$rootScope.$digest();
15+
expect(element.attr('href')).toEqual('http://server');
16+
}));
17+
18+
19+
it('should bind href even if no interpolation', inject(function($rootScope, $compile) {
20+
element = $compile('<a ng-href="http://server"></a>')($rootScope)
1421
$rootScope.$digest();
1522
expect(element.attr('href')).toEqual('http://server');
1623
}));

0 commit comments

Comments
 (0)