From 9cb57772a4030925318475fe93bc19e2916b37bf Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Wed, 17 Nov 2010 21:23:23 -0800 Subject: fix docs for angular.directive and ng:autobind --- src/Angular.js | 223 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 126 insertions(+), 97 deletions(-) (limited to 'src') diff --git a/src/Angular.js b/src/Angular.js index 6a22b027..32187927 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -97,20 +97,18 @@ var _undefined = undefined, * @ngdoc overview * @name angular.directive * @namespace Namespace for all directives. + * * @description - * A directive is an XML attribute that you can use in an existing HTML - * element type or in a DOM element type that you create using - * `angular.widget`, to modify that element's properties. You can use - * any number of directives per element. + * A directive is an HTML attribute that you can use in an existing HTML element type or in a + * DOM element type that you create as {@link angular.widget}, to modify that element's + * properties. You can use any number of directives per element. * - * For example, you can add the ng:bind directive as an attribute of an - * HTML span element, as in ``. - * How does this work? The compiler passes the attribute value `1+2` - * to the ng:bind extension, which in turn tells the Scope to watch - * that expression and report changes. On any change it sets the span - * text to the expression value. + * For example, you can add the ng:bind directive as an attribute of an HTML span element, as in + * ``. How does this work? The compiler passes the attribute value + * `1+2` to the ng:bind extension, which in turn tells the {@link angular.scope} to watch that + * expression and report changes. On any change it sets the span text to the expression value. * - * Here's how to define ng:bind: + * Here's how to define {@link angular.directive.ng:bind ng:bind}: *
angular.directive('ng:bind', function(expression, compiledElement) {
var compiler = this;
@@ -123,36 +121,31 @@ var _undefined = undefined,
});
*
*
- * ## Directive vs. Attribute Widget
- * Both attribute widgets and directives can compile a DOM element
- * attribute. So why have two different ways to do the same thing?
- * The answer is that order matters, but you have no control over
- * the order in which attributes are read. To solve this we
- * apply attribute widget before the directive.
+ * # Directive vs. Attribute Widget
+ * Both [attribute widgets](#!angular.widget) and directives can compile a DOM element
+ * attribute. So why have two different ways to do the same thing? The answer is that order
+ * matters, but we have no control over the order in which attributes are read. To solve this
+ * we apply attribute widget before the directive.
*
- * For example, consider this piece of HTML, which uses the
- * directives `ng:repeat`, `ng:init`, and `ng:bind`:
+ * For example, consider this piece of HTML, which uses the directives `ng:repeat`, `ng:init`,
+ * and `ng:bind`:
*
<!doctype html>
<html xmlns:ng="http://angularjs.org">
<head>
- <script type="text/javascript" ng:autobind
- src="http://code.angularjs.org/angular-0.9.3.min.js"></script>
+ <script type="text/javascript" src="http://code.angularjs.org/angular-0.9.3.min.js"
+ ng:autobind></script>
</head>
<body>
Hello {{'world'}}!
</body>
</html>
*
- *
- * The `ng:autobind` attribute tells
+ <!doctype html>
+ <html>
+ <head>
+ <script type="text/javascript"
+ src="http://code.angularjs.org/angular-0.9.3.min.js#autobind"></script>
+ </head>
+ <body>
+ <div xmlns:ng="http://angularjs.org">
+ Hello {{'world'}}!
+ </div>
+ </body>
+ </html>
+ *
+ *
+ * In this case it's the `#autobind` URL fragment that tells angular to auto-bootstrap.
+ *
+ *
+ * ## Filename Restrictions for Auto-bootstrap
+ * In order for us to find the auto-bootstrap script attribute or URL fragment, the value of the
+ * `script` `src` attribute that loads angular script must match one of these naming
+ * conventions:
+ *
+ * - `angular.js`
+ * - `angular-min.js`
+ * - `angular-x.x.x.js`
+ * - `angular-x.x.x.min.js`
+ * - `angular-x.x.x-xxxxxxxx.js` (dev snapshot)
+ * - `angular-x.x.x-xxxxxxxx.min.js` (dev snapshot)
+ * - `angular-bootstrap.js` (used for development of angular)
+ *
+ * Optionally, any of the filename format above can be prepended with relative or absolute URL that
+ * ends with `/`.
+ *
+ *
+ * ## Manual Bootstrap
+ * Using auto-bootstrap is a handy way to start using
<!doctype html>
<html xmlns:ng="http://angularjs.org">
<head>
- <script type="text/javascript" ng:autobind
- src="http://code.angularjs.org/angular-0.9.3.min.js"></script>
+ <script type="text/javascript" src="http://code.angularjs.org/angular-0.9.3.min.js"
+ ng:autobind></script>
<script type="text/javascript">
(function(window, previousOnLoad){
window.onload = function(){
@@ -968,39 +999,37 @@ function toKeyValue(obj) {
</html>
*
*
- * This is the sequence that your code should follow if you're writing
- * your own manual binding code:
+ * This is the sequence that your code should follow if you're bootstrapping angular on your own:
*
- * * After the page is loaded, find the root of the HTML template,
- * which is typically the root of the document.
- * * Run the HTML compiler, which converts the templates into an
- * executable, bi-directionally bound application.
- *
- * #XML Namespace
- * *IMPORTANT:* When using * <html xmlns:ng="http://angularjs.org"> *- * - * # Create your own namespace - * If you want to define your own widgets, you must create your own - * namespace and use that namespace to form the fully qualified - * widget name. For example, you could map the alias `my` to your - * domain and create a widget called my:widget. To create your own - * namespace, simply add another xmlsn tag to your page, create an - * alias, and set it to your unique domain: + * + * + * ## Create your own namespace + * If you want to define your own widgets, you must create your own namespace and use that namespace + * to form the fully qualified widget name. For example, you could map the alias `my` to your domain + * and create a widget called my:widget. To create your own namespace, simply add another xmlsn tag + * to your page, create an alias, and set it to your unique domain: * *
* <html xmlns:ng="http://angularjs.org" xmlns:my="http://mydomain.com"> *- * - * # Global Object - * The