aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisko Hevery2012-04-03 15:03:27 -0700
committerMisko Hevery2012-04-03 16:02:20 -0700
commit2f5dba488e855bcdbb9304aa809efcb9de7b43e9 (patch)
tree73312f69811d1257b76eaf986ff5c6628adb5898
parent7e86eacf301934335c22908ec6dbd1a083d88fab (diff)
downloadangular.js-2f5dba488e855bcdbb9304aa809efcb9de7b43e9.tar.bz2
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.
-rw-r--r--src/ng/directive/booleanAttrDirs.js16
-rw-r--r--test/ng/directive/booleanAttrDirSpecs.js9
2 files changed, 20 insertions, 5 deletions
diff --git a/src/ng/directive/booleanAttrDirs.js b/src/ng/directive/booleanAttrDirs.js
index f0182610..01134998 100644
--- a/src/ng/directive/booleanAttrDirs.js
+++ b/src/ng/directive/booleanAttrDirs.js
@@ -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);
- });
+ }
};
}
};
diff --git a/test/ng/directive/booleanAttrDirSpecs.js b/test/ng/directive/booleanAttrDirSpecs.js
index 7a4244a8..aa84c1ae 100644
--- a/test/ng/directive/booleanAttrDirSpecs.js
+++ b/test/ng/directive/booleanAttrDirSpecs.js
@@ -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');
}));