mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-23 19:40:56 +08:00
fix(ngRepeat): make allowed aliasAs expressions more strict
Ensure that aliasAs expressions are valid simple identifiers. These are still assigned to $scope in the same way
that they were previously, however now you won't accidentally create a property named "filtered.collection".
This change additionally restricts identifiers to prevent the use of certain ECMAScript reserved words ("null",
"undefined", "this" --- should probably add "super", "try", "catch" and "finally" there too), as well as certain
properties used by $scope or ngRepeat, including $parent, $index, $even, $odd, $first, $middle, or $last.
Closes #8438
Closes #8440
This commit is contained in:
39
docs/content/error/ngRepeat/badident.ngdoc
Normal file
39
docs/content/error/ngRepeat/badident.ngdoc
Normal file
@@ -0,0 +1,39 @@
|
||||
@ngdoc error
|
||||
@name ngRepeat:badident
|
||||
@fullName Invalid identifier expression
|
||||
@description
|
||||
|
||||
Occurs when an invalid identifier is specified in an {@link ng.directive:ngRepeat ngRepeat} expression.
|
||||
|
||||
The {@link ng.directive:ngRepeat ngRepeat} directive's `alias as` syntax is used to assign an alias for the processed collection in scope.
|
||||
|
||||
If the expression is not a simple identifier (such that you could declare it with `var {name}`, or if the expression is a reserved name,
|
||||
this error is thrown.
|
||||
|
||||
Reserved names include:
|
||||
|
||||
- `null`
|
||||
- `this`
|
||||
- `undefined`
|
||||
- `$parent`
|
||||
- `$even`
|
||||
- `$odd`
|
||||
- `$first`
|
||||
- `$last`
|
||||
- `$middle`
|
||||
|
||||
Invalid expressions might look like this:
|
||||
|
||||
```html
|
||||
<li ng-repeat="item in items | filter:searchString as this">{{item}}</li>
|
||||
<li ng-repeat="item in items | filter:searchString as some.objects["property"]">{{item}}</li>
|
||||
<li ng-repeat="item in items | filter:searchString as resultOfSomeMethod()">{{item}}</li>
|
||||
<li ng-repeat="item in items | filter:searchString as foo=6">{{item}}</li>
|
||||
```
|
||||
|
||||
Valid expressions might look like this:
|
||||
|
||||
```html
|
||||
<li ng-repeat="item in items | filter:searchString as collections">{{item}}</li>
|
||||
<li ng-repeat="item in items | filter:searchString as filteredCollection">{{item}}</li>
|
||||
```
|
||||
Reference in New Issue
Block a user