mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-25 06:13:44 +00:00
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.
This commit is contained in:
parent
7e86eacf30
commit
2f5dba488e
2 changed files with 20 additions and 5 deletions
|
|
@ -302,13 +302,21 @@ forEach(['src', 'href'], function(attrName) {
|
||||||
var normalized = directiveNormalize('ng-' + attrName);
|
var normalized = directiveNormalize('ng-' + attrName);
|
||||||
ngAttributeAliasDirectives[normalized] = function() {
|
ngAttributeAliasDirectives[normalized] = function() {
|
||||||
return {
|
return {
|
||||||
priority: 100,
|
priority: 99, // it needs to run after the attributes are interpolated
|
||||||
compile: function(tpl, attr) {
|
compile: function(tpl, attr) {
|
||||||
return function(scope, element, attr) {
|
return function(scope, element, attr) {
|
||||||
attr.$$observers[attrName] = [];
|
var value = attr[normalized];
|
||||||
attr.$observe(normalized, function(value) {
|
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);
|
attr.$set(attrName, value);
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,14 @@ describe('boolean attr directives', function() {
|
||||||
|
|
||||||
it('should bind href', inject(function($rootScope, $compile) {
|
it('should bind href', inject(function($rootScope, $compile) {
|
||||||
element = $compile('<a ng-href="{{url}}"></a>')($rootScope)
|
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();
|
$rootScope.$digest();
|
||||||
expect(element.attr('href')).toEqual('http://server');
|
expect(element.attr('href')).toEqual('http://server');
|
||||||
}));
|
}));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue