diff --git a/src/ng/directive/booleanAttrs.js b/src/ng/directive/booleanAttrs.js index e98a61034063..d7bb0336d015 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,11 +379,21 @@ forEach(['src', 'srcset', 'href'], function(attrName) { propName = null; } - attr.$observe(normalized, function(value) { - if (!value) - return; + var parsed = $interpolate(element.attr(attr.$attr[normalized])); + + scope.$watchGroup(parsed.expressions, function (values) { + var merged = ''; + for (var i = 0, ii = values.length; i < ii; i++) { + if (isDefined(values[i])) { + merged += parsed.separators[i] + values[i]; + } else { + return; + } + } - attr.$set(name, value); + merged += parsed.separators[values.length]; + + attr.$set(name, merged); // on IE, if "ng:src" directive declaration is used and "src" attribute doesn't exist // then calling element.setAttribute('src', 'foo') doesn't do anything, so we need @@ -393,5 +403,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(); })); });