Skip to content

Commit f2c8767

Browse files
docs(guide/expression): update diff list between JavaScript and Angular expressions
add paragraphs about function declaration, comma and void operators and RegExp to the diff list in the beginning of articule Closes angular#10418 Closes angular#10452
1 parent efd0490 commit f2c8767

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

docs/content/guide/expression.ngdoc

+15-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,16 @@ Angular expressions are like JavaScript expressions with the following differenc
2626
* **Forgiving:** In JavaScript, trying to evaluate undefined properties generates `ReferenceError`
2727
or `TypeError`. In Angular, expression evaluation is forgiving to `undefined` and `null`.
2828

29-
* **No Control Flow Statements:** you cannot use the following in an Angular expression:
29+
* **No Control Flow Statements:** You cannot use the following in an Angular expression:
3030
conditionals, loops, or exceptions.
31+
32+
* **No Function Declarations:** You cannot decleare functions in an Angular expression.
33+
Even inside `ng-init` directive
34+
35+
* **No RegExp Creation With Literal Notation:** You cannot create regular expressions
36+
in an Angular expression.
37+
38+
* **No Comma And Void Operators:** You cannot use `,` or `void` in an Angular expression.
3139

3240
* **Filters:** You can use {@link guide/filter filters} within expressions to format data before
3341
displaying it.
@@ -164,6 +172,12 @@ expression. The reason behind this is core to the Angular philosophy that applic
164172
be in controllers, not the views. If you need a real conditional, loop, or to throw from a view
165173
expression, delegate to a JavaScript method instead.
166174

175+
## No function declarations or RegExp creation with literal notation
176+
177+
You can't declare functions or create regular expressions from within AngularJS expressions. This is
178+
to avoid complex model transformation logic inside templates. Such logic is better placed in a
179+
controller or in a dedicated filter where it can be tested properly.
180+
167181
## `$event`
168182

169183
Directives like {@link ng.directive:ngClick `ngClick`} and {@link ng.directive:ngFocus `ngFocus`}

0 commit comments

Comments
 (0)