aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSamuel Santos2013-05-07 17:45:28 +0100
committerPete Bacon Darwin2013-05-14 21:29:21 +0100
commitd551d72924f7c43a043e4760ff05d7389e310f99 (patch)
tree1c7f46aee3b08d439921b32e4469193eefb19f25 /src
parent629fb37351ce5778a40a8bc8cd7c1385b382ce75 (diff)
downloadangular.js-d551d72924f7c43a043e4760ff05d7389e310f99.tar.bz2
feat(ngSrcset): add new ngSrcset directive
In line with ngSrc and ngHref, this new directive ensures that the `srcset` HTML5 attribute does not include a pre-interpolated string. Without it the browser will fetch from the URL with the literal text `{{hash}}` until AngularJS replaces the expression inside `{{hash}}`. Closes #2601
Diffstat (limited to 'src')
-rw-r--r--src/ng/directive/booleanAttrs.js29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/ng/directive/booleanAttrs.js b/src/ng/directive/booleanAttrs.js
index 7e0e3a42..8f7399a6 100644
--- a/src/ng/directive/booleanAttrs.js
+++ b/src/ng/directive/booleanAttrs.js
@@ -107,6 +107,31 @@
/**
* @ngdoc directive
+ * @name ng.directive:ngSrcset
+ * @restrict A
+ *
+ * @description
+ * Using Angular markup like `{{hash}}` in a `srcset` attribute doesn't
+ * work right: The browser will fetch from the URL with the literal
+ * text `{{hash}}` until Angular replaces the expression inside
+ * `{{hash}}`. The `ngSrcset` directive solves this problem.
+ *
+ * The buggy way to write it:
+ * <pre>
+ * <img srcset="http://www.gravatar.com/avatar/{{hash}} 2x"/>
+ * </pre>
+ *
+ * The correct way to write it:
+ * <pre>
+ * <img ng-srcset="http://www.gravatar.com/avatar/{{hash}} 2x"/>
+ * </pre>
+ *
+ * @element IMG
+ * @param {template} ngSrcset any string which can contain `{{}}` markup.
+ */
+
+/**
+ * @ngdoc directive
* @name ng.directive:ngDisabled
* @restrict A
*
@@ -325,8 +350,8 @@ forEach(BOOLEAN_ATTR, function(propName, attrName) {
});
-// ng-src, ng-href are interpolated
-forEach(['src', 'href'], function(attrName) {
+// ng-src, ng-srcset, ng-href are interpolated
+forEach(['src', 'srcset', 'href'], function(attrName) {
var normalized = directiveNormalize('ng-' + attrName);
ngAttributeAliasDirectives[normalized] = function() {
return {