From 829c28f3eec83175715b0eef2693d348fdd3406f Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 8 Dec 2014 14:29:04 -0800 Subject: [PATCH] docs: initial version of the documentation --- .../change_detection/docs/change_detection.md | 8 + modules/change_detection/docs/expressions.md | 7 + modules/change_detection/docs/record.md | 3 + modules/core/docs/00_index.md | 3 + modules/core/docs/01_templates.md | 590 ++++++++++++++++++ modules/core/docs/02_directives.md | 341 ++++++++++ modules/core/docs/03_formatters.md | 15 + modules/core/docs/04_decorator_directive.md | 0 modules/core/docs/05_component_directive.md | 5 + .../core/docs/06_instantiator_directive.md | 0 modules/core/docs/07_services.md | 0 modules/core/docs/08_lifecycle.md | 0 modules/core/docs/09_compilation.md | 21 + modules/core/docs/10_view.md | 209 +++++++ modules/core/docs/11_shadow_dom.md | 0 modules/core/docs/12_zones.md | 105 ++++ 16 files changed, 1307 insertions(+) create mode 100644 modules/change_detection/docs/change_detection.md create mode 100644 modules/change_detection/docs/expressions.md create mode 100644 modules/change_detection/docs/record.md create mode 100644 modules/core/docs/00_index.md create mode 100644 modules/core/docs/01_templates.md create mode 100644 modules/core/docs/02_directives.md create mode 100644 modules/core/docs/03_formatters.md create mode 100644 modules/core/docs/04_decorator_directive.md create mode 100644 modules/core/docs/05_component_directive.md create mode 100644 modules/core/docs/06_instantiator_directive.md create mode 100644 modules/core/docs/07_services.md create mode 100644 modules/core/docs/08_lifecycle.md create mode 100644 modules/core/docs/09_compilation.md create mode 100644 modules/core/docs/10_view.md create mode 100644 modules/core/docs/11_shadow_dom.md create mode 100644 modules/core/docs/12_zones.md diff --git a/modules/change_detection/docs/change_detection.md b/modules/change_detection/docs/change_detection.md new file mode 100644 index 0000000000..4a6f8dd63f --- /dev/null +++ b/modules/change_detection/docs/change_detection.md @@ -0,0 +1,8 @@ +# Change Detection + +* Mechanisms by which changes are detected in the model +* DAG +* Order of evaluation +* Pure Functions +* `onChange` method +* Parser diff --git a/modules/change_detection/docs/expressions.md b/modules/change_detection/docs/expressions.md new file mode 100644 index 0000000000..e9cdc9aa9b --- /dev/null +++ b/modules/change_detection/docs/expressions.md @@ -0,0 +1,7 @@ +# Expressions + +## Binding Semantics + +### Formatters + +## Statement Semantics \ No newline at end of file diff --git a/modules/change_detection/docs/record.md b/modules/change_detection/docs/record.md new file mode 100644 index 0000000000..343624acec --- /dev/null +++ b/modules/change_detection/docs/record.md @@ -0,0 +1,3 @@ +# Record + +## RecordRange \ No newline at end of file diff --git a/modules/core/docs/00_index.md b/modules/core/docs/00_index.md new file mode 100644 index 0000000000..95c575cf1b --- /dev/null +++ b/modules/core/docs/00_index.md @@ -0,0 +1,3 @@ +# Overview + +* High level description of all of the components. \ No newline at end of file diff --git a/modules/core/docs/01_templates.md b/modules/core/docs/01_templates.md new file mode 100644 index 0000000000..adc898c58f --- /dev/null +++ b/modules/core/docs/01_templates.md @@ -0,0 +1,590 @@ +# Templates + +Templates are markup which is added to HTML to declarativly describe how the application model should be +projected to DOM as well as which DOM events should invoke which methods on the controller. Templates contain +syntax which is core to Angular and allows for data-binding, event-binding, template-instantiation. + +The design of template syntax has these properties: + +* All data-binding expressions are easily identifiable. (i.e. there is never an ambiguity wether the value should be + interpreted as string literal or as an expression.) +* All events and their statments are easily identifiable. +* All places of DOM instantiation are easily identifiable. +* All places of variable declaration is esily identifiable. + +The above properties guarantee that the templates are easy to parse by tools (such as IDEs) and reason about by people. +At no point is it necessary to understand which directives are active and what are their symantics in order to reason +about the template runtime characteristics. + + + +## Summary + +Below is a summary of the kinds of syntaxes which Angular templating supports. The syntaxes are explained in more +detail in fallowing sections. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
DescriptionShortCanonical
Text Interpolation +`
{{exp}}
` + +Example: +``` +
+ Hello {{name}}! +
+ Goodbye {{name}}! +
+``` +
+`
` + +Example: +``` +
+ _x_ +
+``` +
Property Interpolation +`
` + +Example: + +`
` +
+`
` + +Example: + +`
` +
Property binding +`
` + +Example: + +`
` +
+`
` + +Example: + +`
` +
Event binding (non-bubbling) +`
` + +Example: + +`
` +
+`
` + +Example: + +`
` +
Event binding (bubbling) +`
` + +Example: + +`
` +
+`
` + +Example: + +`
` +
Declare reference +`
` + +Example: + +``` +
+`
` + +Example: + +``` +
Inline Template +`
...
` + +Example: + +``` +
    +
  • + {{item}} +
  • +
+``` +
+`` + +Example: +``` +
    + +
+``` +
Explicit Template +`` + +Example: + +``` + +``` + +`` + +Example: +``` + +``` +
+ + + +## Property Binding + +Binding application model data to the UI, is the most common kinds of bindings in an Angular application. The bindings +are always in the form of `property-name` which is assigned an `expression`. The generic form is: + + + + + + + + + + +
Short form``
Canonical form``
+ + +Where: +* `some-element` can be any existing DOM element. +* `some-property` (escaped with `[]` or `bind-`) is the name of the property on `some-element`. In this case the + dash-case is converted into camel-case `someProperty`. +* `expression` is a valid expression (as defined in section below). + +Example: +``` +
+``` + +In the above example the `title` property of the `div` element will be updated whenever the `user.firstName` changes +its value. + +Key points: +* The binding is to the element property not the element attribute. +* To prevent custom element from accidentaly reading the literal `expression` on the title element, the attribute name + is escaped. In our case the `title` is escaped to `[title]` through the addition of squre brackets `[]`. +* A binding value (in this case `user.firstName` will always be an expression, never a string literal) + +NOTE: Unlike Angular v1, Angular v2 binds to properties of elements rather than attributes of elements. This is +done to better support custom elements, and allow binding for values other than strings. + +NOTE: Some editors/server side pre-processors may have trouble generating `[]` arround the attribute name. For this +reason Angular also supports a canonical version which is prefixed using `bind-`. + + + +### String Interpolation + +Property bindings are the only data bindings which angular supports, but for convenience Angular supports interpolation +syntax which is just a short hand for the data binding syntax. + +``` +Hello {{name}}! +``` + +is a short hand for: + +``` +_ +``` + +The above says to bind `'Hello ' + stringify(name) + '!'` expression to the zero-th child of the `span`'s `text` +property. The index is necessary in case there are more than one text nodes, or if the text node we wish to bind to +is not the first one. + +Similarly the same rules apply to interpolation inside attributes. + +``` + +``` + +is a short hand for: + +``` + +``` + +NOTE: `stringify()` is a built in implicit function which converts its argument to a string representation, while +keeping `null` and `undefined` as empty strings. + + + + +## Local Varibles + + + + +## Inline Templates + +Data binding allows updating the DOM's properties, but it does not allow for changing of the DOM structure. To change +DOM structure we need the ability to define child templates, and than instantiat these templates into Views. The +Views can than be inserted and removed as needed to change the DOM structure. + + + + + + + + + + +
Short form +``` +parent template + + child template + +``` +
Canonical form +``` +parent template + + + +``` +
+ +Where: +* `template` defines a child template and designates the anchor where Views (instances of the template) will be + inserted. The template can be defined implicitly with `template` attribute, which turns the current element into + a template, or explicitly with `