diff --git a/src/ng/directive/booleanAttrs.js b/src/ng/directive/booleanAttrs.js index e98a61034063..ba491095c1fb 100644 --- a/src/ng/directive/booleanAttrs.js +++ b/src/ng/directive/booleanAttrs.js @@ -365,7 +365,7 @@ forEach(BOOLEAN_ATTR, function(propName, attrName) { // ng-src, ng-srcset, ng-href are interpolated forEach(['src', 'srcset', 'href'], function(attrName) { var normalized = directiveNormalize('ng-' + attrName); - ngAttributeAliasDirectives[normalized] = function() { + ngAttributeAliasDirectives[normalized] = ['$interpolate', function($interpolate) { return { priority: 99, // it needs to run after the attributes are interpolated link: function(scope, element, attr) { @@ -379,9 +379,13 @@ forEach(['src', 'srcset', 'href'], function(attrName) { propName = null; } - attr.$observe(normalized, function(value) { - if (!value) - return; + var iterpolateFn = $interpolate(element.attr(attr.$attr[normalized])); + + scope.$watchGroup(iterpolateFn.expressions, function (values) { + var value = iterpolateFn(scope, true); + if (isUndefined(value)) { + return; + } attr.$set(name, value); @@ -393,5 +397,5 @@ forEach(['src', 'srcset', 'href'], function(attrName) { }); } }; - }; + }]; }); diff --git a/test/ng/directive/booleanAttrsSpec.js b/test/ng/directive/booleanAttrsSpec.js index 6bcb57eeb2b8..bfa563a731fc 100644 --- a/test/ng/directive/booleanAttrsSpec.js +++ b/test/ng/directive/booleanAttrsSpec.js @@ -204,7 +204,7 @@ describe('ngSrcset', function() { var element = $compile('
')($rootScope); $rootScope.$digest(); - expect(element.attr('srcset')).toEqual('some/ 2x'); + expect(element.attr('srcset')).toEqual(); $rootScope.$apply(function() { $rootScope.id = 1; @@ -227,7 +227,7 @@ describe('ngHref', function() { it('should interpolate the expression and bind to href', inject(function($compile, $rootScope) { element = $compile('')($rootScope); $rootScope.$digest(); - expect(element.attr('href')).toEqual('some/'); + expect(element.attr('href')).toEqual(); $rootScope.$apply(function() { $rootScope.id = 1; @@ -258,7 +258,7 @@ describe('ngHref', function() { element = $compile('')($rootScope); var child = element.children('a'); $rootScope.$digest(); - expect(child.attr('xlink:href')).toEqual('some/'); + expect(child.attr('xlink:href')).toEqual(); $rootScope.$apply(function() { $rootScope.id = 1; diff --git a/test/ng/directive/ngSrcsetSpec.js b/test/ng/directive/ngSrcsetSpec.js index 8fccb00ae906..2e621eb496b2 100644 --- a/test/ng/directive/ngSrcsetSpec.js +++ b/test/ng/directive/ngSrcsetSpec.js @@ -11,6 +11,6 @@ describe('ngSrcset', function() { $rootScope.image = {}; element = $compile('')($rootScope); $rootScope.$digest(); - expect(element.attr('srcset')).toEqual(' 2x'); + expect(element.attr('srcset')).toEqual(); })); });