parent
40d0505782
commit
538b0879dc
@ -29,60 +29,74 @@ detail in the following sections.
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Description</th><th>Short</th><th>Canonical</th>
|
<th>Description</th><th>Short</th><th>Canonical</th>
|
||||||
</tr>
|
</tr>
|
||||||
<thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Text Interpolation</th>
|
<th>Text Interpolation</th>
|
||||||
<td>
|
<td>
|
||||||
```html
|
<pre>
|
||||||
|
```
|
||||||
<div>{{exp}}</div>
|
<div>{{exp}}</div>
|
||||||
```
|
```
|
||||||
|
</pre>
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
```html
|
<pre>
|
||||||
|
```
|
||||||
<div>
|
<div>
|
||||||
Hello {{name}}!
|
Hello {{name}}!
|
||||||
<br>
|
<br>
|
||||||
Goodbye {{name}}!
|
Goodbye {{name}}!
|
||||||
</div>
|
</div>
|
||||||
```
|
```
|
||||||
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
`<div [text|index]=exp>`
|
`<div [text|index]=exp>`
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
```html
|
<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>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Property Interpolation</th>
|
<th>Property Interpolation</th>
|
||||||
<td>
|
<td>
|
||||||
```html
|
<pre>
|
||||||
|
```
|
||||||
<div name="{{exp}}">
|
<div name="{{exp}}">
|
||||||
```
|
```
|
||||||
|
</pre>
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```html
|
<pre>
|
||||||
|
```
|
||||||
<div class="{{selected}}">`
|
<div class="{{selected}}">`
|
||||||
```
|
```
|
||||||
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
```html
|
<pre>
|
||||||
|
```
|
||||||
<div [name]="stringify(exp)">
|
<div [name]="stringify(exp)">
|
||||||
```
|
```
|
||||||
|
</pre>
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```html
|
<pre>
|
||||||
|
```
|
||||||
<div [class]="stringify(selected)">
|
<div [class]="stringify(selected)">
|
||||||
```
|
```
|
||||||
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@ -143,20 +157,24 @@ Example:
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
<pre>
|
||||||
```
|
```
|
||||||
<video #player>
|
<video #player>
|
||||||
<button (click)="player.play()">play</button>
|
<button (click)="player.play()">play</button>
|
||||||
```
|
```
|
||||||
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
`<div def="symbol">`
|
`<div def="symbol">`
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
<pre>
|
||||||
```
|
```
|
||||||
<video def="player">
|
<video def="player">
|
||||||
<button on-click="player.play()">play</button>
|
<button on-click="player.play()">play</button>
|
||||||
```
|
```
|
||||||
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@ -166,6 +184,7 @@ Example:
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
<pre>
|
||||||
```
|
```
|
||||||
<ul>
|
<ul>
|
||||||
<li template="foreach: #item in items">
|
<li template="foreach: #item in items">
|
||||||
@ -173,11 +192,13 @@ Example:
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
```
|
```
|
||||||
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
`<template>...</template>`
|
`<template>...</template>`
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
<pre>
|
||||||
```
|
```
|
||||||
<ul>
|
<ul>
|
||||||
<template def-foreach:"item"
|
<template def-foreach:"item"
|
||||||
@ -188,6 +209,7 @@ Example:
|
|||||||
</template>
|
</template>
|
||||||
</ul>
|
</ul>
|
||||||
```
|
```
|
||||||
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@ -197,23 +219,27 @@ Example:
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
<pre>
|
||||||
```
|
```
|
||||||
<template #foreach="item"
|
<template #foreach="item"
|
||||||
[foreach-in]="items">
|
[foreach-in]="items">
|
||||||
_some_content_to_repeat_
|
_some_content_to_repeat_
|
||||||
</template>
|
</template>
|
||||||
```
|
```
|
||||||
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
`<template>...</template>`
|
`<template>...</template>`
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
<pre>
|
||||||
```
|
```
|
||||||
<template def-foreach="item"
|
<template def-foreach="item"
|
||||||
bind-foreach-in="items">
|
bind-foreach-in="items">
|
||||||
_some_content_to_repeat_
|
_some_content_to_repeat_
|
||||||
</template>
|
</template>
|
||||||
```
|
```
|
||||||
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -538,22 +564,22 @@ Angular are:
|
|||||||
<div template="if: expression">...</div>
|
<div template="if: expression">...</div>
|
||||||
```
|
```
|
||||||
|
|
||||||
Expressions are a simplified version of an expression in the language in which you are writing your application. (i.e.
|
Expressions are simplified version of expression in the language in which you are writing your application. (i.e.
|
||||||
expressions follow JS syntax and semantics in JS and Dart syntax and semantics in Dart). Unlike expressions in the
|
expressions follow JS syntax and semantics in JS and Dart syntax and semantics in Dart). Unlike expressions in the
|
||||||
language, binding expressions behave differently in the following ways:
|
language, binding expressions behave differently in following ways:
|
||||||
|
|
||||||
* *Must be defined*: Unlike Angular v1, Angular v2 will throw an error on dereferencing fields which are not defined.
|
* *Must be defined*: Unlike Angular v1, Angular v2 will throw an error on dereferencing fields which are not defined.
|
||||||
For example: `user.name` will throw an error if `user` is defined but it does not have a `name` property. If the `name`
|
For example: `user.name` will throw an error if `user` is defined but it does not have `name` property. If the `name`
|
||||||
property is not known, it must be declared and set to some value such as an empty string, `null` (or `undefined` in JS).
|
property is not known, it must be declared and set to some value such as empty string, `null` (or `undefined` in JS).
|
||||||
This is done to allow early detection of errors in the templates.
|
This is done to allow early detection of errors in the templates.
|
||||||
* *Safe dereference*: Expression `user.name` where `user` is `null` will throw a `NullPointerException` in the language.
|
* *Safe dereference*: Expressions `user.name` where `user` is null will throw `NullPointerException` in the language.
|
||||||
In contrast Angular will silently ignore `null` on `user`. This is done because Views often have to wait for the data
|
In contrast Angular will silently ignore `null` on `user`. This is done because Views often have to wait for the data
|
||||||
to arrive from the backend and many fields will be `null` until the data arrives. Safe dereference is so common in the
|
to arrive from the backend and many fields will be `null` until the data arrives. Safe dereference is so common in the
|
||||||
Views that we have made it the default.
|
Views that we have made it the default.
|
||||||
* *Single expression*: An expression must be a single statement. (i.e. no `;`)
|
* *Single expression*: An expression must be a single statement. (i.e. no `;`)
|
||||||
* *No assignments*: Binding expressions can not contain assignments.
|
* *No assignments*: Binding expressions can not contain assignments.
|
||||||
* *No keywords*: Binding expressions can not contain keywords such as: `var`, `if`, and so on.
|
* *No keywords*: Binding expressions can not contain keywords such as: `var`, `if`, and so on.
|
||||||
* *Formatters*: Angular expressions can be piped through formatters to further transform the binding value.
|
* *Formatters*: Angular expressions can be piped through formatters to further transform the binding value.
|
||||||
(See: Formatters)
|
(See: Formatters)
|
||||||
|
|
||||||
Examples of some expressions and their behavior:
|
Examples of some expressions and their behavior:
|
||||||
@ -566,7 +592,7 @@ class Greeter {
|
|||||||
```
|
```
|
||||||
|
|
||||||
* `name` : Will result in the value of the `name` property on the `Greeter` class.
|
* `name` : Will result in the value of the `name` property on the `Greeter` class.
|
||||||
* `name.length`: Will result in either the length of the `name` string or `undefined` (`null` in Dart) if `name`
|
* `name.length`: Will result in either the length of the `name` string or `undefined` (`null` in Dart) if `name`
|
||||||
property is `null` or `undefined`. Example of: safe dereference.
|
property is `null` or `undefined`. Example of: safe dereference.
|
||||||
* `foo`: Will throw an error because `foo` is not declared on the `Greeter` class. Example of: Must be defined
|
* `foo`: Will throw an error because `foo` is not declared on the `Greeter` class. Example of: Must be defined
|
||||||
* `name=1`: Not allowed because of assignment.
|
* `name=1`: Not allowed because of assignment.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user