My First Angular Application
Interpolation The syntax format for interpolation is: {{ ... }}. Interpolation can insert calculated strings into HTML, and can also be used as attribute values.
{{title}}
Template Expressions
{{ ... }} actually contains a template expression, which Angular evaluates and converts to string output.
The following example is adding two numbers:
The sum of 1 + 1 is {{1 + 1}}
We can use getVal() to get the value of this expression:{{1 + 1 + getVal()}}
Template expressions are similar to JavaScript, many JavaScript expressions are also valid template expressions, but not all. The following JavaScript expressions are prohibited: Assignment expressions (=, +=, -=...) new operator Concatenation expressions with ; or ' Increment and decrement operators (++ and --) Other things different from JavaScript syntax that are worth noting: Bitwise operators (| and &) are not supported Template expression operators like | and ?. have been given new meanings Property Binding Property binding in templates can set view element properties to template expression values. The most common property binding is setting an element's property to the value of a component property. In the following example, the image element's src property will be bound to the component's imageUrl property: bound to classes property
Set a custom component's property (this is an important way for parent-child component communication):
HTML Attribute, Class and Style Bindings
Template syntax provides dedicated one-way data binding forms for scenarios where property binding is not suitable.
Attribute Binding
When an element has no property to bind, use HTML attribute binding.
Consider ARIA, SVG, and table colspan/rowspan attributes. They are pure attributes. They have no corresponding properties to bind.
The following example will error:
| One-Two | |
| Five | Six |
YouTip