@@ -101,7 +101,7 @@ include ../../../../_includes/_util-fns
101
101
We write template expressions in a language that looks like JavaScript.
102
102
Many JavaScript expressions are legal template expressions but not all.
103
103
JavaScript expressions that have or promote side-effects are prohibited including:
104
- * assignment (`=`)
104
+ * assignments (`=`, `+=`, `- =`)
105
105
* the `new` operator
106
106
* chaining expressions with `;` or `,`
107
107
* increment and decrement operators, `++` and `--`.
@@ -191,11 +191,12 @@ include ../../../../_includes/_util-fns
191
191
:marked
192
192
Angular template statements are also written in a language that looks like JavaScript.
193
193
The template statement parser is different than the template expression parser and
194
- specifically supports both assignment (=) and chaining expressions with semicolons (;) and commas (,).
194
+ specifically supports both basic assignment (=) and chaining expressions with semicolons (;) and commas (,).
195
195
196
196
However, certain JavaScript syntax is not allowed:
197
197
* the `new` operator
198
198
* increment and decrement operators, `++` and `--`
199
+ * operator assignment, e.g. `+=`, `-=`
199
200
* bit-wise operators, `|` and `&`
200
201
* the [template expression operators](#expression-operators)
201
202
@@ -1172,28 +1173,30 @@ figure.image-display
1172
1173
1173
1174
This is frequently the case with [Attribute Directives](attribute-directives.html).
1174
1175
Directive consumers expect to bind to the name of the directive.
1175
- For example, we expect to bind to the `myClick` event property of the `MyClickDirective`.
1176
-
1177
- The directive name is often a poor choice for the the internal property name
1178
- because it rarely describes what the property does.
1179
- `myClick` is not a good name for a property that emits click events.
1176
+ For example, when we apply a directive with a `myClick` selector to a `<div>` tag,
1177
+ we expect to bind to an event property that is also called `myClick`.
1178
+ + makeExample('template-syntax/ts/app/app.component.html' , 'my-click' )( format ="." )
1179
+ :marked
1180
+ However, the directive name is often a poor choice for the the name of a property within the directive class.
1181
+ The directive name rarely describes what the property does.
1182
+ The `myClick` directive name is not a good name for a property that emits click messages.
1180
1183
1181
1184
Fortunately, we can have a public name for the property that meets conventional expectations
1182
- and use a different name internally
1183
- by providing a public alias for the internal property name in the decorator like this:
1185
+ while using a different name internally.
1186
+ In the example immediately above, we are actually binding *through the* `myClick` *alias* to
1187
+ the directive's own `clicks` property.
1188
+
1189
+ We can specify the alias for the property name by passing it into the input/output decorator like this:
1190
+
1184
1191
+ makeExample('template-syntax/ts/app/my-click.directive.ts' , 'my-click-output-1' )( format ="." )
1185
1192
:marked
1186
- Now the directive name, `myClick`, is the public facing property name to which we can bind
1187
- + makeExample('template-syntax/ts/app/app.component.html' , 'my-click' )( format ="." )
1188
- :marked
1189
- while inside the directive, the property is known as `clicks`.
1193
+
1190
1194
1191
- With aliasing we please both the directive consumer and the directive author.
1192
1195
.l-sub-section
1193
1196
:marked
1194
- We can alias property names in the `inputs` and `outputs` arrays as well .
1195
- We write a colon-delimited string with
1196
- the internal property name on the left and the public name on the right:
1197
+ We can also alias property names in the `inputs` and `outputs` arrays.
1198
+ We write a * colon-delimited* (:) string with
1199
+ the directive property name on the * left* and the public alias on the * right* :
1197
1200
+ makeExample('template-syntax/ts/app/my-click.directive.ts' , 'my-click-output-2' )( format ="." )
1198
1201
1199
1202
<a id =" expression-operators" ></a >
0 commit comments