Skip to content

Commit bd33f60

Browse files
mheveryIgorMinar
authored andcommitted
Added part of guide documentation and supporting changes to doc generator
1 parent 8682bef commit bd33f60

18 files changed

Lines changed: 861 additions & 127 deletions

docs/guide.bootstrap.ngdoc

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
@workInProgress
2+
@ngdoc overview
3+
@name Developer Guide: Bootstrap
4+
@description
5+
6+
# Bootstrap
7+
This section explains how to bootstrap your application to the angular environment using either
8+
the `angular.js` or `angular.min.js` script.
9+
10+
## The bootstrap code
11+
12+
Note that there are two versions of the bootstrap code that you can use:
13+
14+
* `angular-0.0.0.js` - this file is unobfuscated, uncompressed, and thus human-readable.
15+
* `angular-0.0.0.min.js` - this is a compressed and obfuscated version of angular-debug.js.
16+
17+
In this section and throughout the Developer Guide, feel free to use `angular.min.js` instead of
18+
`angular.js` when working through code examples.
19+
20+
## ng:autobind
21+
22+
The simplest way to get an angular application up and running is by inserting a script tag in your
23+
HTML file that bootstraps the `angular.js` code and uses the special `ng:autobind` attribute,
24+
like in this snippet of HTML:
25+
26+
<doc:example>
27+
<doc:source>
28+
Hello {{'World'}}!
29+
</doc:source>
30+
</doc:example>
31+
32+
The `ng:autobind` attribute tells angular to compile and manage the whole HTML document. The
33+
compilation occurs in the page's onLoad handler. Note that you don't need to explicitly add an
34+
onLoad event; auto bind mode takes care of all the magic for you.
35+
36+
## Manual bind
37+
38+
Using autobind mode is a handy way to start using angular, but advanced users who want more
39+
control over the initialization process might prefer to use manual bind mode instead.
40+
41+
The best way to get started with manual bind mode is to look at the magic behind `ng:autobind`
42+
by writing out each step of the autobind process explicitly. Note that the following code is
43+
equivalent to the code in the previous section.
44+
45+
<pre>
46+
<!DOCTYPE HTML>
47+
<html xmlns:ng="http://angularjs.org">
48+
<script type="text/javascript" src="http://code.angularjs.org/angular-0.0.0.min.js"></script>
49+
<script type="text/javascript">
50+
(function(window, previousOnLoad){
51+
window.onload = function(){
52+
try { (previousOnLoad||angular.noop)(); } catch(e) {}
53+
angular.compile(window.document).$init();
54+
};
55+
})(window, window.onload);
56+
</script>
57+
<body>
58+
Hello {{'World'}}!
59+
</body>
60+
</html>
61+
</pre>
62+
63+
This is the sequence that your code should follow if you're writing your own manual binding code:
64+
65+
* After the page is loaded, find the root of the HTML template, which is typically the root of
66+
the document.
67+
* Run the HTML compiler, which converts the templates into an executable, bi-directionally
68+
bound application.
69+
70+
71+
# XML Namespace
72+
73+
**IMPORTANT:** When using angular you must declare the `ng` namespace using the `xmlns` tag.
74+
If you don't declare the namespace, Internet Explorer does not render widgets properly.
75+
76+
<pre>
77+
<html xmlns:ng="http://angularjs.org">
78+
</pre>
79+
80+
81+
# Create your own namespace
82+
83+
If you want to define your own widgets, you must create your own namespace and use that namespace
84+
to form the fully qualified widget name. For example, you could map the alias my to your domain
85+
and create a widget called my:widget. To create your own namespace, simply add another xmlsn tag
86+
to your page, create an alias, and set it to your unique domain:
87+
88+
<pre>
89+
<html xmlns:my="http://mydomain.com">
90+
</pre>
91+
92+
93+
# Global Object
94+
95+
The angular script creates a single global variable `angular` in the global namespace. All APIs are
96+
bound to fields of this global object.
97+

docs/guide.compiler.ngdoc

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
@workInProgress
2+
@ngdoc overview
3+
@name Developer Guide: Compiler
4+
@description
5+
6+
#Compiler
7+
8+
While angular might look like just a cool way to build web applications, the core of angular is
9+
actually an HTML compiler. The default HTML transformations that this compiler provides are useful
10+
for building generic apps, but you can also use them to create a domain-specific language for
11+
building specific types of web applications.
12+
13+
The compiler allows you to add behavior to existing HTML through widgets, directives, and text
14+
markup.
15+
16+
All of this compilation happens in the web browser, meaning no server is involved.
17+
18+
# The compilation process
19+
This section describes the steps that angular's HTML compiler goes through. If you use
20+
`ng:autobind` in your application, this compilation process happens automatically when the
21+
application is initialized (e.g. when the user loads the app in a browser). If you're an advanced
22+
user using manual bind mode, you can decide when and how often the compilation happens.
23+
24+
First, a bit of background of what the compilation step is for. Every type of
25+
{@link angular.widget widget}, {@link angular.markup markup}, and
26+
{@link angular.directive directive} in angular is defined with a compile function, and that
27+
compile function returns an optional link function. Here is the relationship between the two:
28+
29+
* **compile function** - registers a listener for the widget, markup, or directive's expression.
30+
This function is called exactly once.
31+
* **link function** - sets up the listener. This function can be called multiple times, once per
32+
cloned DOM element (e.g. repeating element).
33+
34+
Note that angular's built-in widgets, markup, and directives have predefined compile and link
35+
functions that you don't need to modify. However, if you're writing your own widgets, markup, or
36+
directives, you write compile and link functions. Refer to the Compiler API for more information.
37+
38+
When the HTML compiler compiles a page, it goes through 3 phases: Compile, Create Root Scope, and
39+
Link.
40+
41+
## 1. Compile Phase
42+
43+
* Recursively traverse the DOM, depth-first.
44+
* Look for a matching compile function of type widget, then markup, then directive.
45+
* If a compile function is found then execute it.
46+
* When the compile function completes, it should return a link function. Aggregate this link
47+
function with all link functions returned previously by step 1c.
48+
* Repeat steps 1c and 1d for all compile functions found. The result of the compilation step is
49+
the aggregate link function, which comprises all of the individual link functions.
50+
51+
## 2. Create Root Scope
52+
53+
* Inject all of the services into the root scope.
54+
55+
## 3. Link Phase
56+
57+
* Execute the aggregate link function with the root scope. The aggregate link function calls all
58+
the individual link functions that were generated in the compile phase.
59+
* If there are any clones of the DOM caused by repeating elements, call the link function multiple
60+
times, one for each repeating item.
61+
62+
Note that while the compile function is executed exactly once, the link function can be executed
63+
multiple times: once for each iteration in a repeater.
64+
65+
# Example
66+
67+
The compilation process is best understood through example. Let's say that in your namespace my,
68+
you want to create a new DOM element <my:greeter/>, which should display a greeting.
69+
70+
If we want this HTML source:
71+
72+
<pre>
73+
<div ng:init="salutation='Hello'; name='World'">
74+
<my:greeter salutation="salutation" name="name"/>
75+
</div>
76+
</pre>
77+
78+
To produce this DOM:
79+
80+
<pre>
81+
<div ng:init="salutation='Hello'; name='World'">
82+
<my:greeter salutation="salutation" name="name"/>
83+
<span class="salutation">Hello</span>
84+
<span class="name">World</span>!
85+
</my:greeter>
86+
</div>
87+
</pre>
88+
89+
Write this widget definition (assuming you've already declared the my namespace in the page):
90+
91+
92+
<pre>
93+
angular.widget('my:greeter', function(compileElement){
94+
var compiler = this;
95+
compileElement.css('display', 'block');
96+
var salutationExp = compileElement.attr('salutation');
97+
var nameExp = compileElement.attr('name');
98+
return function(linkElement){
99+
var salutationSpan = angular.element('<span class="salutation"></span');
100+
var nameSpan = angular.element('<span class="name"></span>');
101+
linkElement.append(salutationSpan);
102+
linkElement.append(compiler.text(' '));
103+
linkElement.append(nameSpan);
104+
linkElement.append(compiler.text('!'));
105+
this.$watch(salutationExp, function(value){
106+
salutationSpan.text(value);
107+
});
108+
this.$watch(nameExp, function(value){
109+
nameSpan.text(value);
110+
});
111+
};
112+
});
113+
</pre>
114+
115+
Note: For more about widgets, see {@link angular.widget Widget}.
116+
117+
## Compilation process for this example
118+
119+
Here are the steps that the compiler goes through for the page that contains this widget definition:
120+
121+
### Compile Phase
122+
123+
* Recursively traverse the DOM depth-first.
124+
* Find the angular.widget definition.
125+
* Find and execute the widget's compileElement function, which includes the following steps:
126+
* Add a style element with attribute display: block; to the template DOM so that the browser
127+
knows to treat the element as block element for rendering. (Note: because this style element
128+
was added on the template compileElement, this style is automatically applied to any clones
129+
of the template (i.e. any repeating elements)).
130+
* Extract the salutation and name HTML attributes as angular expressions.
131+
* Return the aggregate link function, which includes just one link function in this example.
132+
133+
### Link Phase
134+
135+
* Execute the aggregate link function, which includes the following steps:
136+
* Create a <span> element set to the salutation class
137+
* Create a <span> element set to the name class.
138+
* Add the span elements to the linkElement. (Note: be careful not to add them to the
139+
compileElement, because that's the template.)
140+
* Set up watches on the expressions. When an expression changes, copy the data to the
141+
corresponding spans.
142+
143+
144+
## Compiler API
145+
146+
If you define your own widgets, markup, or directives, you need to access the compiler API.
147+
This section describes the methods on the compiler that you can call.
148+
149+
Note: As of 12 August 2010, these methods are subject to change.
150+
151+
Recall that the compile function's this is a reference to the compiler.
152+
153+
* `compile(element)` - returns `linker` - Invoke new instance of compiler to compile a DOM element
154+
and return a linker function. You can apply the linker function to the original element or a
155+
clone of the original element. The linker function returns a scope.
156+
* `comment(commentText)` - returns `element` - Create a comment element.
157+
* `element(elementName)` - returns `element` - Create an element by name.
158+
* `text(text)` - returns `element` - Create a text element.
159+
* `descend([set])` - returns `descend` - State Get or set the current descend state. If true the
160+
compiler will descend to children elements.
161+
* `directives([set])` - returns `directive` - State Get or set the current directives processing
162+
state. The compiler will process directives only when directives set to true.
163+

docs/guide.data-binding.ngdoc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@workInProgress
2+
@ngdoc overview
3+
@name Developer Guide: Data Binding
4+
@description
5+
6+
# Data Binding
7+
8+
Data-binding allows you to treat the model as the single-source-of-truth of your application, and
9+
consider the view as only a projection of the model, at all times. The process of copying the model
10+
values to the view, and any changes to the view by the user to the model, is known as data-binding.
11+
12+
## Classical Template Systems
13+
14+
<img class="right" src="img/One_Way_Data_Binding.png"/>
15+
At the highest level, angular looks like a just another templating system. But there is one
16+
important reason why angular templating system is different and makes it very good fit for
17+
application development: two-way data binding.
18+
19+
Most templating systems bind data in only one direction: they merge a template and model together
20+
into a view, as illustrated in the diagram to the right. After the merge occurs, any changes to
21+
the model or in related sections of the view are NOT automatically reflected in the view. Worse,
22+
any changes that the user makes to the view are not reflected in the model. This means that the
23+
developer has to write code that constantly syncs the view with the model and the model with the
24+
view.
25+
26+
27+
# angular Template Systems
28+
<img class="right" src="img/Two_Way_Data_Binding.png"/>
29+
The way angular templates works is different, as illustrated in the diagram on the right. They are
30+
different because first the template (which is the uncompiled HTML along with any additional markup
31+
or directives) is compiled on the browser, and second, the compilation step produces a live view.
32+
We say live because any changes to the view are immediately reflected in the model, and any changes
33+
in the model are propagated to the view. This makes the model always the single-source-of-truth for
34+
the application state, greatly simplifying the programing model for the developer. You can think of
35+
the view as simply an instant projection of your model.
36+
37+
Because the view is just a projection of the model, the controller is completely separated from the
38+
view and unaware of it. This makes testing a snap because it is easy to test your controller in
39+
isolation without the view and the related DOM/browser dependency.
40+
41+
For details about how data binding works in angular, see {@link angular.scope Scope}.

docs/guide.ngdoc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@workInProgress
2+
@ngdoc overview
3+
@name Developer Guide
4+
@description
5+
6+
* {@link guide.overview Overview} - An overview of angular, including its philosophy and how it
7+
works.
8+
* {@link guide.bootstrap Bootstrap} - How to bootstrap your application to the angular environment.
9+
* {@link guide.template Template} - How to define your application's view using HTML, CSS, and
10+
other built-in angular constructs.
11+
* {@link guide.compiler Compiler} - All about the HTML compiler that's at the core of angular.
12+
* {@link angular.directive Directive} - How to use XML attributes to augment an existing DOM
13+
element.
14+
* {@link angular.markup Markup} - How to use markup to create shorthand for a widget or a
15+
directive. For example, markup is what allows you to use the double curly brace notation
16+
`{{}}` to bind expressions to elements.
17+
* {@link guide.data-binding Data Binding} - About the mechanism that keeps the model the single
18+
source of truth of your application at all times, with the view as a live projection of the
19+
model.
20+
* {@link angular.filter Filter} - How to format your data for display to the user.
21+
* {@link angular.widget Widget} - How to create new DOM elements that the browser doesn't already
22+
understand.
23+
* {@link angular.validator Validator} - How to validate user input.
24+
* {@link angular.formatter Formatter} - How to format stored data to user-readable text and
25+
parse the text back to the stored form.
26+
* {@link guide.css CSS} - Built-in CSS classes, when angular assigns them, and how to override
27+
their styles.
28+
* {@link angular.scope Scope} - The model in the model-view-controller design pattern. You can
29+
think about scopes as the JavaScript objects that have extra APIs for registering watchers.
30+
* {@link guide.expression Expression} - The bindings that are embedded in an angular View.
31+
* {@link angular.service Service} - Objects that are wired through dependency injection and then
32+
injected into the root scope.
33+
* {@link guide.testing Testing}
34+
* service:$browser(mock)
35+
* {@link guide.downloading Downloading} - How to download, compile, and host the angular
36+
environment on your own server.

0 commit comments

Comments
 (0)