Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
docs(ng:bind-attr): improve examples
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorMinar committed Nov 8, 2011
1 parent 66fc268 commit 9f9ed4c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,28 @@ angularDirective("ng:bind-template", function(expression, element){
*
* Instead of writing `ng:bind-attr` statements in your HTML, you can use double-curly markup to
* specify an <tt ng:non-bindable>{{expression}}</tt> for the value of an attribute.
* At compile time, the attribute is translated into an `<span ng:bind-attr="{attr:expression}"/>`
* At compile time, the attribute is translated into an
* `<span ng:bind-attr="{attr:expression}"></span>`.
*
* The following HTML snippet shows how to specify `ng:bind-attr`:
* <pre>
* <a href="http://www.google.com/search?q={{query}}">Google</a>
* <a ng:bind-attr='{"href":"http://www.google.com/search?q={{query}}"}'>Google</a>
* </pre>
*
* During compilation, the snippet gets translated to the following:
* This is cumbersome, so as we mentioned using double-curly markup is a prefered way of creating
* this binding:
* <pre>
* <a ng:bind-attr='{"href":"http://www.google.com/search?q={{query}}"}'>Google</a>
* <a href="http://www.google.com/search?q={{query}}">Google</a>
* </pre>
*
* During compilation, the template with attribute markup gets translated to the ng:bind-attr form
* mentioned above.
*
* _Note_: You might want to consider using {@link angular.directive.ng:href ng:href} instead of
* `href` if the binding is present in the main application template (`index.html`) and you want to
* make sure that a user is not capable of clicking on raw/uncompiled link.
*
*
* @element ANY
* @param {string} attribute_json one or more JSON key-value pairs representing
* the attributes to replace with expressions. Each key matches an attribute
Expand All @@ -406,7 +416,11 @@ angularDirective("ng:bind-template", function(expression, element){
<div ng:controller="Ctrl">
Google for:
<input type="text" ng:model="query"/>
<a ng:bind-attr='{"href":"http://www.google.com/search?q={{query}}"}'>
Google
</a> (ng:bind-attr) |
<a href="http://www.google.com/search?q={{query}}">Google</a>
(curly binding in attribute val)
</div>
</doc:source>
<doc:scenario>
Expand Down

0 comments on commit 9f9ed4c

Please sign in to comment.