8000 docs(ngRepeat): clarify limitations of object iteration · rvpatkar/angular.js@4ba8e34 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4ba8e34

Browse files
committed
docs(ngRepeat): clarify limitations of object iteration
Related angular#6266
1 parent 9881e77 commit 4ba8e34

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/ng/directive/ngRepeat.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,23 @@
3636
* <div ng-repeat="(key, value) in myObj"> ... </div>
3737
* ```
3838
*
39-
* You need to be aware that the JavaScript specification does not define the order of keys
40-
* returned for an object. (To mitigate this in Angular 1.3 the `ngRepeat` directive
41-
* used to sort the keys alphabetically.)
39+
* However, there are a limitations compared to array iteration:
4240
*
43-
* Version 1.4 removed the alphabetic sorting. We now rely on the order returned by the browser
44-
* when running `for key in myObj`. It seems that browsers generally follow the strategy of providing
45-
* keys in the order in which they were defined, although there are exceptions when keys are deleted
46-
* and reinstated. See the [MDN page on `delete` for more info](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete#Cross-browser_notes).
41+
* - The JavaScript specification does not define the order of keys
42+
* returned for an object, so Angular relies on the order returned by the browser
43+
* when running `for key in myObj`. Browsers generally follow the strategy of providing
44+
* keys in the order in which they were defined, although there are exceptions when keys are deleted
45+
* and reinstated. See the
46+
* [MDN page on `delete` for more info](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete#Cross-browser_notes).
4747
*
48-
* If this is not desired, the recommended workaround is to convert your object into an array
49-
* that is sorted into the order that you prefer before providing it to `ngRepeat`. You could
48+
* - `ngRepeat` will silently *ignore* object keys starting with `$`, because
49+
* it's a prefix used by Angular for public (`$`) and private (`$$`) properties.
50+
*
51+
* - The built-in filters {@link ng.orderBy orderBy} and {@link ng.filter filter} do not work with
52+
* objects, and will throw if used with one.
53+
*
54+
* If you are hitting any of these limitations, the recommended workaround is to convert your object into an array
55+
* that is sorted into the order that you prefer before providing it to `ngRepeat`. You could
5056
* do this with a filter such as [toArrayFilter](http://ngmodules.org/modules/angular-toArrayFilter)
5157
* or implement a `$watch` on the object yourself.
5258
*

0 commit comments

Comments
 (0)
0