forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular.directive.ng:bind-attr.html
42 lines (41 loc) · 2.23 KB
/
angular.directive.ng:bind-attr.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<h1>angular.directive.ng:bind-attr</h1>
<div class="angular-directive-ng-bind-attr"><fieldset class="workInProgress"><legend>Work in Progress</legend>
This page is currently being revised. It might be incomplete or contain inaccuracies.</fieldset>
<h2>Description</h2>
<div class="description"><p>The <code>ng:bind-attr</code> attribute specifies that the element attributes
which should be replaced by the expression in it. Unlike <code>ng:bind</code>
the <code>ng:bind-attr</code> contains a JSON key value pairs representing
which attributes need to be changed. You don’t usually write the
<code>ng:bind-attr</code> in the HTML since embedding
<tt ng:non-bindable>{{expression}}</tt> into the
attribute directly is the preferred way. The attributes get
translated into <code><span ng:bind-attr="{attr:expression}"/></code> at
bootstrap time.</p>
<p>This HTML snippet is preferred way of working with <code>ng:bind-attr</code></p><div ng:non-bindable><pre class="brush: js; html-script: true;">
<a href="http://www.google.com/search?q={{query}}">Google</a>
</pre></div><p>The above gets translated to bellow during bootstrap time.</p><div ng:non-bindable><pre class="brush: js; html-script: true;">
<a ng:bind-attr='{"href":"http://www.google.com/search?q={{query}}"}'>Google</a>
</pre></div></div>
<h2>Dependencies</h2>
<ul class="dependencies"></ul>
<h2>Usage</h2>
<div class="usage"><pre class="brush: js; html-script: true;"><ANY ng:bind-attr="attribute_json">
...
</ANY></pre>
<h3>Parameters</h3>
<ul class="parameters"><li><code ng:non-bindable="">attribute_json – {string} – </code>
<p>a JSON key-value pairs representing
the attributes to replace. Each key matches the attribute
which needs to be replaced. Each value is a text template of
the attribute with embedded
<tt ng:non-bindable>{{expression}}</tt>s. Any number of
key-value pairs can be specified.</p></li>
</ul>
</div>
<h2>Example</h2>
<div class="example"><p>Try it here: enter text in text box and click Google.</p><doc:example><doc:source>Google for:
<input type="text" name="query" value="AngularJS"/>
<a href="http://www.google.com/search?q={{query}}">Google</a></doc:source>
</doc:example>
</div>
</div>