aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorLuis Ramón López2013-02-26 00:00:47 +0100
committerIgor Minar2013-02-27 00:55:40 -0800
commitcf17c6af475eace31cf52944afd8e10d3afcf6c0 (patch)
treeaa552c9f6b8af0ff0ed208ec6c3a5574432a4109 /docs
parent86d191ed4aea9015adc71b852223475c5c762c34 (diff)
downloadangular.js-cf17c6af475eace31cf52944afd8e10d3afcf6c0.tar.bz2
feat($compile): add attribute binding support via ngAttr*
Sometimes is not desirable to use interpolation on attributes because the user agent parses them before the interpolation takes place. I.e: <svg> <circle cx="{{cx}}" cy="{{cy}}" r="{{r}}"></circle> </svg> The snippet throws three browser errors, one for each attribute. For some attributes, AngularJS fixes that behaviour introducing special directives like ng-href or ng-src. This commit is a more general solution that allows prefixing any attribute with "ng-attr-", "ng:attr:" or "ng_attr_" so it will be set only when the binding is done. The prefix is then removed. Example usage: <svg> <circle ng-attr-cx="{{cx}}" ng-attr-cy="{{cy}}" ng:attr-r="{{r}}"></circle> </svg> Closes #1050 Closes #1925
Diffstat (limited to 'docs')
-rw-r--r--docs/content/guide/directive.ngdoc27
1 files changed, 26 insertions, 1 deletions
diff --git a/docs/content/guide/directive.ngdoc b/docs/content/guide/directive.ngdoc
index da1dc6df..59b89b40 100644
--- a/docs/content/guide/directive.ngdoc
+++ b/docs/content/guide/directive.ngdoc
@@ -53,7 +53,7 @@ the following example.
</doc:scenario>
</doc:example>
-# String interpolation
+# Text and attribute bindings
During the compilation process the {@link api/ng.$compile compiler} matches text and
attributes using the {@link api/ng.$interpolate $interpolate} service to see if they
@@ -66,6 +66,31 @@ here:
<a href="img/{{username}}.jpg">Hello {{username}}!</a>
</pre>
+
+# ngAttr attribute bindings
+
+If an attribute with a binding is prefixed with `ngAttr` prefix (denormalized prefix: 'ng-attr-',
+'ng:attr-') then during the compilation the prefix will be removed and the binding will be applied
+to an unprefixed attribute. This allows binding to attributes that would otherwise be eagerly
+processed by browsers in their uncompilled form (e.g. `img[src]` or svg's `circle[cx]` attributes).
+
+For example, considering template:
+
+ <svg>
+ <circle ng-attr-cx="{{cx}}"></circle>
+ </svg>
+
+and model cx set to 5, will result in rendering this dom:
+
+ <svg>
+ <circle cx="5"></circle>
+ </svg>
+
+If you were to bind `{{cx}}` directly to the `cx` attribute, you'd get the following error:
+`Error: Invalid value for attribute cx="{{cx}}"`. With `ng-attr-cx` you can work around this
+problem.
+
+
# Compilation process, and directive matching
Compilation of HTML happens in three phases: