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
|
||||
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:
|
||||
|
||||
|
@ -35,34 +35,30 @@ detail in the following sections.
|
|||
<th>Text Interpolation</th>
|
||||
<td>
|
||||
<pre>
|
||||
```
|
||||
<div>{{exp}}</div>
|
||||
```
|
||||
<div>{{exp}}</div>
|
||||
</pre>
|
||||
|
||||
Example:
|
||||
<pre>
|
||||
```
|
||||
<div>
|
||||
<div>
|
||||
Hello {{name}}!
|
||||
<br>
|
||||
<br>
|
||||
Goodbye {{name}}!
|
||||
</div>
|
||||
```
|
||||
</div>
|
||||
</pre>
|
||||
</td>
|
||||
<td>
|
||||
`<div [text|index]=exp>`
|
||||
<pre>
|
||||
<div [text|index]="exp"></div>
|
||||
</pre>
|
||||
|
||||
Example:
|
||||
<pre>
|
||||
```
|
||||
<div
|
||||
<div
|
||||
[text|0]=" 'Hello' + stringify(name) + '!' "
|
||||
[text|2]=" 'Goodbye' + stringify(name) + '!' ">
|
||||
_<b>x</b>_
|
||||
</div>
|
||||
```
|
||||
[text|2]=" 'Goodbye' + stringify(name) + '!' ">
|
||||
<b>x</b>
|
||||
</div>
|
||||
</pre>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -70,148 +66,156 @@ Example:
|
|||
<th>Property Interpolation</th>
|
||||
<td>
|
||||
<pre>
|
||||
```
|
||||
<div name="{{exp}}">
|
||||
```
|
||||
<div name="{{exp}}"></div>
|
||||
</pre>
|
||||
|
||||
Example:
|
||||
|
||||
<pre>
|
||||
```
|
||||
<div class="{{selected}}">`
|
||||
```
|
||||
<div class="{{selected}}"></div>
|
||||
</pre>
|
||||
</td>
|
||||
<td>
|
||||
<pre>
|
||||
```
|
||||
<div [name]="stringify(exp)">
|
||||
```
|
||||
<div [name]="stringify(exp)"></div>
|
||||
</pre>
|
||||
|
||||
Example:
|
||||
|
||||
<pre>
|
||||
```
|
||||
<div [title]="stringify(selected)">
|
||||
```
|
||||
<div [title]="stringify(selected)"></div>
|
||||
</pre>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Property binding</th>
|
||||
<td>
|
||||
`<div [prop]="exp">`
|
||||
<pre>
|
||||
<div [prop]="exp"></div>
|
||||
</pre>
|
||||
|
||||
Example:
|
||||
|
||||
`<div [hidden]="true">`
|
||||
<pre>
|
||||
<div [hidden]="true"></div>
|
||||
</pre>
|
||||
</td>
|
||||
<td>
|
||||
`<div bind-prop="exp">`
|
||||
<pre>
|
||||
<div bind-prop="exp"></div>
|
||||
</pre>
|
||||
|
||||
Example:
|
||||
|
||||
`<div bind-hidden="true">`
|
||||
<pre>
|
||||
<div bind-hidden="true"></div>
|
||||
</pre>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Event binding (non-bubbling)</th>
|
||||
<td>
|
||||
`<div (event)="statement">`
|
||||
|
||||
Example:
|
||||
|
||||
`<div (click)="doX()">`
|
||||
</td>
|
||||
<td>
|
||||
`<div on-event="statement">`
|
||||
<pre>
|
||||
<div (event)="statement"></div>
|
||||
</pre>
|
||||
|
||||
Example:
|
||||
|
||||
<pre>
|
||||
```
|
||||
<video #player>
|
||||
<button (click)="player.play()">play</button>
|
||||
```
|
||||
<div (click)="doX()"></div>
|
||||
</pre>
|
||||
</td>
|
||||
<td>
|
||||
`<div def="symbol">`
|
||||
<pre>
|
||||
<div on-event="statement"></div>
|
||||
</pre>
|
||||
|
||||
Example:
|
||||
|
||||
<pre>
|
||||
```
|
||||
<video def="player">
|
||||
<button on-click="player.play()">play</button>
|
||||
```
|
||||
<video #player>
|
||||
<button (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>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Inline Template</th>
|
||||
<td>
|
||||
`<div template="...">...</div>`
|
||||
<pre>
|
||||
<div template="...">...</div>
|
||||
</pre>
|
||||
|
||||
Example:
|
||||
|
||||
<pre>
|
||||
```
|
||||
<ul>
|
||||
<li template="for: #item of items">
|
||||
<ul>
|
||||
<li template="for: #item of items">
|
||||
{{item}}
|
||||
</li>
|
||||
</ul>
|
||||
```
|
||||
</li>
|
||||
</ul>
|
||||
</pre>
|
||||
</td>
|
||||
<td>
|
||||
`<template>...</template>`
|
||||
<pre>
|
||||
<template>...</template>
|
||||
</pre>
|
||||
|
||||
Example:
|
||||
<pre>
|
||||
```
|
||||
<ul>
|
||||
<template def-for:"item"
|
||||
bind-for-in="items">
|
||||
<li>
|
||||
<ul>
|
||||
<template def-for:"item"
|
||||
bind-for-in="items">
|
||||
<li>
|
||||
{{item}}
|
||||
</li>
|
||||
</template>
|
||||
</ul>
|
||||
```
|
||||
</li>
|
||||
</template>
|
||||
</ul>
|
||||
</pre>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Explicit Template</th>
|
||||
<td>
|
||||
`<template>...</template>`
|
||||
<pre>
|
||||
<template>...</template>
|
||||
</pre>
|
||||
|
||||
Example:
|
||||
|
||||
<pre>
|
||||
```
|
||||
<template #for="item"
|
||||
[for-in]="items">
|
||||
<template #for="item"
|
||||
[for-in]="items">
|
||||
_some_content_to_repeat_
|
||||
</template>
|
||||
```
|
||||
</template>
|
||||
</pre>
|
||||
</td>
|
||||
<td>
|
||||
`<template>...</template>`
|
||||
<pre>
|
||||
<template>...</template>
|
||||
</pre>
|
||||
|
||||
Example:
|
||||
|
||||
<pre>
|
||||
```
|
||||
<template def-for="item"
|
||||
bind-for-in="items">
|
||||
<template def-for="item"
|
||||
bind-for-in="items">
|
||||
_some_content_to_repeat_
|
||||
</template>
|
||||
```
|
||||
</template>
|
||||
</pre>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -228,11 +232,11 @@ are always in the form of `property-name` which is assigned an `expression`. The
|
|||
<table>
|
||||
<tr>
|
||||
<th>Short form</th>
|
||||
<td>`<some-element [some-property]="expression">`</td>
|
||||
<td><pre><some-element [some-property]="expression"></pre></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Canonical form</th>
|
||||
<td>`<some-element bind-some-property="expression">`</td>
|
||||
<td><pre><some-element bind-some-property="expression"></pre></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
@ -255,7 +259,7 @@ Key points:
|
|||
* 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
|
||||
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
|
||||
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:
|
||||
|
||||
```
|
||||
<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`
|
||||
|
@ -317,25 +321,25 @@ Views than can be inserted and removed as needed to change the DOM structure.
|
|||
<tr>
|
||||
<th>Short form</th>
|
||||
<td>
|
||||
```
|
||||
<pre>
|
||||
parent template
|
||||
<element>
|
||||
<some-element template="instantiating-directive-microsyntax">child template</some-element>
|
||||
</element>
|
||||
```
|
||||
<element>
|
||||
<some-element template="instantiating-directive-microsyntax">child template</some-element>
|
||||
</element>
|
||||
</pre>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Canonical form</th>
|
||||
<td>
|
||||
```
|
||||
<pre>
|
||||
parent template
|
||||
<element>
|
||||
<template instantiating-directive-bindings>
|
||||
<some-element>child template</some-element>
|
||||
</template>
|
||||
</element>
|
||||
```
|
||||
<element>
|
||||
<template instantiating-directive-bindings>
|
||||
<some-element>child template</some-element>
|
||||
</template>
|
||||
</element>
|
||||
</pre>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -448,7 +452,7 @@ microsyntax: ([[key|keyExpression|varExport][;|,]?)*
|
|||
```
|
||||
|
||||
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.
|
||||
* `internal` is an internal variable which the directive exports for binding.
|
||||
* `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>
|
||||
<tr>
|
||||
<th>Short form</th>
|
||||
<td>`<some-element (some-event)="statement">`</td>
|
||||
<td><pre><some-element (some-event)="statement"></pre></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Canonical form</th>
|
||||
<td>`<some-element on-some-event="statement">`</td>
|
||||
<td><pre><some-element on-some-event="statement"></pre></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
@ -493,11 +497,11 @@ Angular listens to bubbled DOM events (as in the case of clicking on any child),
|
|||
<table>
|
||||
<tr>
|
||||
<th>Short form</th>
|
||||
<td>`<some-element (some-event)="statement">`</td>
|
||||
<td><pre><some-element (some-event)="statement"></pre></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Canonical form</th>
|
||||
<td>`<some-element on-some-event="statement">`</td>
|
||||
<td><pre><some-element on-some-event="statement"></pre></td>
|
||||
</tr>
|
||||
</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
|
||||
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.
|
||||
|
||||
|
||||
|
@ -534,7 +538,7 @@ have different semantics.
|
|||
### Expressions
|
||||
|
||||
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:
|
||||
```
|
||||
<div title="{{expression}}">{{expression}}</div>
|
||||
|
|
Loading…
Reference in New Issue