docs: cleanup
According to dictionary 'syntax' is countable and according to context it should be plural. fix the broken table of template summary. fix the table in Property Binding. fix a position of right parethesis in Property Binding. fix a occurance of a non-sense underscore. fix a table in Inline Templates. fix a missing '.' in Template Microsyntax. fix the table in '## Binding Events'. fix an article usage of 'an' against 'a' in '## Binding Events'. fix a statement against the usage of plural after 'any'. fix the typo error in former fixes. Closes #3994
This commit is contained in:
parent
a826f22698
commit
4df0604f09
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
Templates are markup which is added to HTML to declaratively describe how the application model should be
|
Templates are markup which is added to HTML to declaratively 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
|
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.
|
syntaxes which are core to Angular and allows for data-binding, event-binding, template-instantiation.
|
||||||
|
|
||||||
The design of the template syntax has these properties:
|
The design of the template syntax has these properties:
|
||||||
|
|
||||||
|
@ -35,34 +35,30 @@ detail in the following sections.
|
||||||
<th>Text Interpolation</th>
|
<th>Text Interpolation</th>
|
||||||
<td>
|
<td>
|
||||||
<pre>
|
<pre>
|
||||||
```
|
<div>{{exp}}</div>
|
||||||
<div>{{exp}}</div>
|
|
||||||
```
|
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
<pre>
|
<pre>
|
||||||
```
|
<div>
|
||||||
<div>
|
|
||||||
Hello {{name}}!
|
Hello {{name}}!
|
||||||
<br>
|
<br>
|
||||||
Goodbye {{name}}!
|
Goodbye {{name}}!
|
||||||
</div>
|
</div>
|
||||||
```
|
|
||||||
</pre>
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
`<div [text|index]=exp>`
|
<pre>
|
||||||
|
<div [text|index]="exp"></div>
|
||||||
|
</pre>
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
<pre>
|
<pre>
|
||||||
```
|
<div
|
||||||
<div
|
|
||||||
[text|0]=" 'Hello' + stringify(name) + '!' "
|
[text|0]=" 'Hello' + stringify(name) + '!' "
|
||||||
[text|2]=" 'Goodbye' + stringify(name) + '!' ">
|
[text|2]=" 'Goodbye' + stringify(name) + '!' ">
|
||||||
_<b>x</b>_
|
<b>x</b>
|
||||||
</div>
|
</div>
|
||||||
```
|
|
||||||
</pre>
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -70,148 +66,156 @@ Example:
|
||||||
<th>Property Interpolation</th>
|
<th>Property Interpolation</th>
|
||||||
<td>
|
<td>
|
||||||
<pre>
|
<pre>
|
||||||
```
|
<div name="{{exp}}"></div>
|
||||||
<div name="{{exp}}">
|
|
||||||
```
|
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
```
|
<div class="{{selected}}"></div>
|
||||||
<div class="{{selected}}">`
|
|
||||||
```
|
|
||||||
</pre>
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<pre>
|
<pre>
|
||||||
```
|
<div [name]="stringify(exp)"></div>
|
||||||
<div [name]="stringify(exp)">
|
|
||||||
```
|
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
```
|
<div [title]="stringify(selected)"></div>
|
||||||
<div [title]="stringify(selected)">
|
|
||||||
```
|
|
||||||
</pre>
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Property binding</th>
|
<th>Property binding</th>
|
||||||
<td>
|
<td>
|
||||||
`<div [prop]="exp">`
|
<pre>
|
||||||
|
<div [prop]="exp"></div>
|
||||||
|
</pre>
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
`<div [hidden]="true">`
|
<pre>
|
||||||
|
<div [hidden]="true"></div>
|
||||||
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
`<div bind-prop="exp">`
|
<pre>
|
||||||
|
<div bind-prop="exp"></div>
|
||||||
|
</pre>
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
`<div bind-hidden="true">`
|
<pre>
|
||||||
|
<div bind-hidden="true"></div>
|
||||||
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Event binding (non-bubbling)</th>
|
<th>Event binding (non-bubbling)</th>
|
||||||
<td>
|
<td>
|
||||||
`<div (event)="statement">`
|
<pre>
|
||||||
|
<div (event)="statement"></div>
|
||||||
Example:
|
</pre>
|
||||||
|
|
||||||
`<div (click)="doX()">`
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
`<div on-event="statement">`
|
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
```
|
<div (click)="doX()"></div>
|
||||||
<video #player>
|
|
||||||
<button (click)="player.play()">play</button>
|
|
||||||
```
|
|
||||||
</pre>
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
`<div def="symbol">`
|
<pre>
|
||||||
|
<div on-event="statement"></div>
|
||||||
|
</pre>
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
```
|
<video #player>
|
||||||
<video def="player">
|
<button (click)="player.play()">play</button>
|
||||||
<button on-click="player.play()">play</button>
|
</video>
|
||||||
```
|
</pre>
|
||||||
|
|
||||||
|
Or:
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<div def="symbol"></div>
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<video def="player">
|
||||||
|
<button on-click="player.play()">play</button>
|
||||||
|
</video>
|
||||||
</pre>
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Inline Template</th>
|
<th>Inline Template</th>
|
||||||
<td>
|
<td>
|
||||||
`<div template="...">...</div>`
|
<pre>
|
||||||
|
<div template="...">...</div>
|
||||||
|
</pre>
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
```
|
<ul>
|
||||||
<ul>
|
<li template="for: #item of items">
|
||||||
<li template="for: #item of items">
|
|
||||||
{{item}}
|
{{item}}
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
```
|
|
||||||
</pre>
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
`<template>...</template>`
|
<pre>
|
||||||
|
<template>...</template>
|
||||||
|
</pre>
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
<pre>
|
<pre>
|
||||||
```
|
<ul>
|
||||||
<ul>
|
<template def-for:"item"
|
||||||
<template def-for:"item"
|
bind-for-in="items">
|
||||||
bind-for-in="items">
|
<li>
|
||||||
<li>
|
|
||||||
{{item}}
|
{{item}}
|
||||||
</li>
|
</li>
|
||||||
</template>
|
</template>
|
||||||
</ul>
|
</ul>
|
||||||
```
|
|
||||||
</pre>
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Explicit Template</th>
|
<th>Explicit Template</th>
|
||||||
<td>
|
<td>
|
||||||
`<template>...</template>`
|
<pre>
|
||||||
|
<template>...</template>
|
||||||
|
</pre>
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
```
|
<template #for="item"
|
||||||
<template #for="item"
|
[for-in]="items">
|
||||||
[for-in]="items">
|
|
||||||
_some_content_to_repeat_
|
_some_content_to_repeat_
|
||||||
</template>
|
</template>
|
||||||
```
|
|
||||||
</pre>
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
`<template>...</template>`
|
<pre>
|
||||||
|
<template>...</template>
|
||||||
|
</pre>
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
```
|
<template def-for="item"
|
||||||
<template def-for="item"
|
bind-for-in="items">
|
||||||
bind-for-in="items">
|
|
||||||
_some_content_to_repeat_
|
_some_content_to_repeat_
|
||||||
</template>
|
</template>
|
||||||
```
|
|
||||||
</pre>
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -228,11 +232,11 @@ are always in the form of `property-name` which is assigned an `expression`. The
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Short form</th>
|
<th>Short form</th>
|
||||||
<td>`<some-element [some-property]="expression">`</td>
|
<td><pre><some-element [some-property]="expression"></pre></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Canonical form</th>
|
<th>Canonical form</th>
|
||||||
<td>`<some-element bind-some-property="expression">`</td>
|
<td><pre><some-element bind-some-property="expression"></pre></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
@ -255,7 +259,7 @@ Key points:
|
||||||
* The binding is to the element property not the element attribute.
|
* The binding is to the element property not the element attribute.
|
||||||
* To prevent custom element from accidentally reading the literal `expression` on the title element, the attribute name
|
* To prevent custom element from accidentally 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 square brackets `[]`.
|
is escaped. In our case the `title` is escaped to `[title]` through the addition of square brackets `[]`.
|
||||||
* A binding value (in this case `user.firstName` will always be an expression, never a string literal).
|
* 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
|
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 to allow binding for values other than strings.
|
done to better support custom elements, and to allow binding for values other than strings.
|
||||||
|
@ -277,7 +281,7 @@ syntax which is just a short hand for the data binding syntax.
|
||||||
is a short hand for:
|
is a short hand for:
|
||||||
|
|
||||||
```
|
```
|
||||||
<span [text|0]=" 'Hello ' + stringify(name) + '!' ">_</span>
|
<span [text|0]=" 'Hello ' + stringify(name) + '!' "></span>
|
||||||
```
|
```
|
||||||
|
|
||||||
The above says to bind the `'Hello ' + stringify(name) + '!'` expression to the zero-th child of the `span`'s `text`
|
The above says to bind the `'Hello ' + stringify(name) + '!'` expression to the zero-th child of the `span`'s `text`
|
||||||
|
@ -317,25 +321,25 @@ Views than can be inserted and removed as needed to change the DOM structure.
|
||||||
<tr>
|
<tr>
|
||||||
<th>Short form</th>
|
<th>Short form</th>
|
||||||
<td>
|
<td>
|
||||||
```
|
<pre>
|
||||||
parent template
|
parent template
|
||||||
<element>
|
<element>
|
||||||
<some-element template="instantiating-directive-microsyntax">child template</some-element>
|
<some-element template="instantiating-directive-microsyntax">child template</some-element>
|
||||||
</element>
|
</element>
|
||||||
```
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Canonical form</th>
|
<th>Canonical form</th>
|
||||||
<td>
|
<td>
|
||||||
```
|
<pre>
|
||||||
parent template
|
parent template
|
||||||
<element>
|
<element>
|
||||||
<template instantiating-directive-bindings>
|
<template instantiating-directive-bindings>
|
||||||
<some-element>child template</some-element>
|
<some-element>child template</some-element>
|
||||||
</template>
|
</template>
|
||||||
</element>
|
</element>
|
||||||
```
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
@ -448,7 +452,7 @@ microsyntax: ([[key|keyExpression|varExport][;|,]?)*
|
||||||
```
|
```
|
||||||
|
|
||||||
Where
|
Where
|
||||||
* `expression` is an Angular expression as defined in section: Expressions
|
* `expression` is an Angular expression as defined in section: Expressions.
|
||||||
* `local` is a local identifier for local variables.
|
* `local` is a local identifier for local variables.
|
||||||
* `internal` is an internal variable which the directive exports for binding.
|
* `internal` is an internal variable which the directive exports for binding.
|
||||||
* `key` is an attribute name usually only used to trigger a specific directive.
|
* `key` is an attribute name usually only used to trigger a specific directive.
|
||||||
|
@ -473,11 +477,11 @@ Binding events allows wiring events from DOM (or other components) to the Angula
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Short form</th>
|
<th>Short form</th>
|
||||||
<td>`<some-element (some-event)="statement">`</td>
|
<td><pre><some-element (some-event)="statement"></pre></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Canonical form</th>
|
<th>Canonical form</th>
|
||||||
<td>`<some-element on-some-event="statement">`</td>
|
<td><pre><some-element on-some-event="statement"></pre></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
@ -493,11 +497,11 @@ Angular listens to bubbled DOM events (as in the case of clicking on any child),
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Short form</th>
|
<th>Short form</th>
|
||||||
<td>`<some-element (some-event)="statement">`</td>
|
<td><pre><some-element (some-event)="statement"></pre></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Canonical form</th>
|
<th>Canonical form</th>
|
||||||
<td>`<some-element on-some-event="statement">`</td>
|
<td><pre><some-element on-some-event="statement"></pre></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
@ -519,7 +523,7 @@ component's controller.
|
||||||
|
|
||||||
|
|
||||||
NOTE: Unlike Angular v1, Angular v2 treats event bindings as core constructs not as directives. This means that there
|
NOTE: Unlike Angular v1, Angular v2 treats event bindings as core constructs not as directives. This means that there
|
||||||
is no need to create a event directive for each kind of event. This makes it possible for Angular v2 to easily
|
is no need to create an event directive for each kind of event. This makes it possible for Angular v2 to easily
|
||||||
bind to custom events of Custom Elements, whose event names are not known ahead of time.
|
bind to custom events of Custom Elements, whose event names are not known ahead of time.
|
||||||
|
|
||||||
|
|
||||||
|
@ -534,7 +538,7 @@ have different semantics.
|
||||||
### Expressions
|
### Expressions
|
||||||
|
|
||||||
Expressions can be used to bind to properties only. Expressions represent how data should be projected to the View.
|
Expressions can be used to bind to properties only. Expressions represent how data should be projected to the View.
|
||||||
Expressions should not have any side effects and should be idempotent. Examples of where expressions can be used in
|
Expressions should not have any side effect and should be idempotent. Examples of where expressions can be used in
|
||||||
Angular are:
|
Angular are:
|
||||||
```
|
```
|
||||||
<div title="{{expression}}">{{expression}}</div>
|
<div title="{{expression}}">{{expression}}</div>
|
||||||
|
|
Loading…
Reference in New Issue