diff options
| author | Caitlin Potter | 2014-01-20 20:59:21 -0500 |
|---|---|---|
| committer | Caitlin Potter | 2014-02-21 17:56:48 -0500 |
| commit | 2bce71e9dc10c8588f9eb599a0cd2e831440fc48 (patch) | |
| tree | 91d711cbef54eb8a642e14b70a573b185cadc1a7 /src | |
| parent | c8e03e34b27a8449d8e1bfe0e3801d6a67ae2c49 (diff) | |
| download | angular.js-2bce71e9dc10c8588f9eb599a0cd2e831440fc48.tar.bz2 | |
feat(ngHref): bind ng-href to xlink:href for SVGAElement
This change makes the ngHref directive useful for SVGAElements by having it bind
to the xlink:href attribute rather than the href attribute.
Closes #5904
Diffstat (limited to 'src')
| -rw-r--r-- | src/ng/directive/booleanAttrs.js | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/ng/directive/booleanAttrs.js b/src/ng/directive/booleanAttrs.js index ff3cf5ee..50f118d4 100644 --- a/src/ng/directive/booleanAttrs.js +++ b/src/ng/directive/booleanAttrs.js @@ -369,17 +369,27 @@ forEach(['src', 'srcset', 'href'], function(attrName) { return { priority: 99, // it needs to run after the attributes are interpolated link: function(scope, element, attr) { + var propName = attrName, + name = attrName; + + if (attrName === 'href' && + toString.call(element.prop('href')) === '[object SVGAnimatedString]') { + name = 'xlinkHref'; + attr.$attr[name] = 'xlink:href'; + propName = null; + } + attr.$observe(normalized, function(value) { if (!value) return; - attr.$set(attrName, value); + attr.$set(name, value); // 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 // to set the property as well to achieve the desired effect. // we use attr[attrName] value since $set can sanitize the url. - if (msie) element.prop(attrName, attr[attrName]); + if (msie && propName) element.prop(propName, attr[name]); }); } }; |
