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

Commit 9f9ed4c

Browse files
committed
docs(ng:bind-attr): improve examples
1 parent 66fc268 commit 9f9ed4c

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/directives.js

+18-4
Original file line numberDiff line numberDiff line change
@@ -374,18 +374,28 @@ angularDirective("ng:bind-template", function(expression, element){
374374
*
375375
* Instead of writing `ng:bind-attr` statements in your HTML, you can use double-curly markup to
376376
* specify an <tt ng:non-bindable>{{expression}}</tt> for the value of an attribute.
377-
* At compile time, the attribute is translated into an `<span ng:bind-attr="{attr:expression}"/>`
377+
* At compile time, the attribute is translated into an
378+
* `<span ng:bind-attr="{attr:expression}"></span>`.
378379
*
379380
* The following HTML snippet shows how to specify `ng:bind-attr`:
380381
* <pre>
381-
* <a href="http://www.google.com/search?q={{query}}">Google</a>
382+
* <a ng:bind-attr='{"href":"http://www.google.com/search?q={{query}}"}'>Google</a>
382383
* </pre>
383384
*
384-
* During compilation, the snippet gets translated to the following:
385+
* This is cumbersome, so as we mentioned using double-curly markup is a prefered way of creating
386+
* this binding:
385387
* <pre>
386-
* <a ng:bind-attr='{"href":"http://www.google.com/search?q={{query}}"}'>Google</a>
388+
* <a href="http://www.google.com/search?q={{query}}">Google</a>
387389
* </pre>
388390
*
391+
* During compilation, the template with attribute markup gets translated to the ng:bind-attr form
392+
* mentioned above.
393+
*
394+
* _Note_: You might want to consider using {@link angular.directive.ng:href ng:href} instead of
395+
* `href` if the binding is present in the main application template (`index.html`) and you want to
396+
* make sure that a user is not capable of clicking on raw/uncompiled link.
397+
*
398+
*
389399
* @element ANY
390400
* @param {string} attribute_json one or more JSON key-value pairs representing
391401
* the attributes to replace with expressions. Each key matches an attribute
@@ -406,7 +416,11 @@ angularDirective("ng:bind-template", function(expression, element){
406416
<div ng:controller="Ctrl">
407417
Google for:
408418
<input type="text" ng:model="query"/>
419+
<a ng:bind-attr='{"href":"http://www.google.com/search?q={{query}}"}'>
420+
Google
421+
</a> (ng:bind-attr) |
409422
<a href="http://www.google.com/search?q={{query}}">Google</a>
423+
(curly binding in attribute val)
410424
</div>
411425
</doc:source>
412426
<doc:scenario>

0 commit comments

Comments
 (0)