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

Commit

Permalink
fix(ng-href): copy even if no binding
Browse files Browse the repository at this point in the history
Closes# 850

fixed an issue where ng-href would not copy its content into href if it did not contain binding.
  • Loading branch information
mhevery committed Apr 3, 2012
1 parent 7e86eac commit 2f5dba4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/ng/directive/booleanAttrDirs.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,21 @@ forEach(['src', 'href'], function(attrName) {
var normalized = directiveNormalize('ng-' + attrName);
ngAttributeAliasDirectives[normalized] = function() {
return {
priority: 100,
priority: 99, // it needs to run after the attributes are interpolated
compile: function(tpl, attr) {
return function(scope, element, attr) {
attr.$$observers[attrName] = [];
attr.$observe(normalized, function(value) {
var value = attr[normalized];
if (value == undefined) {
// undefined value means that the directive is being interpolated
// so just register observer
attr.$$observers[attrName] = [];
attr.$observe(normalized, function(value) {
attr.$set(attrName, value);
});
} else {
// value present means that no interpolation, so copy to native attribute.
attr.$set(attrName, value);
});
}
};
}
};
Expand Down
9 changes: 8 additions & 1 deletion test/ng/directive/booleanAttrDirSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ describe('boolean attr directives', function() {

it('should bind href', inject(function($rootScope, $compile) {
element = $compile('<a ng-href="{{url}}"></a>')($rootScope)
$rootScope.url = 'http://server'
$rootScope.url = 'http://server';
$rootScope.$digest();
expect(element.attr('href')).toEqual('http://server');
}));


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

0 comments on commit 2f5dba4

Please sign in to comment.