Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 7fab29f

Browse files
docs(ngRepeat): document the sorting of object keys
See #6210
1 parent 1a47fcb commit 7fab29f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/ng/directive/ngRepeat.js

+23
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,29 @@
2323
* Creating aliases for these properties is possible with {@link ng.directive:ngInit `ngInit`}.
2424
* This may be useful when, for instance, nesting ngRepeats.
2525
*
26+
* # Iterating over object properties
27+
*
28+
* It is possible to get `ngRepeat` to iterate over the properties of an object using the following
29+
* syntax:
30+
*
31+
* ```js
32+
* <div ng-repeat="(key, value) in myObj"> ... </div>
33+
* ```
34+
*
35+
* You need to be aware that the JavaScript specification does not define what order
36+
* it will return the keys for an object. In order to have a guaranteed deterministic order
37+
* for the keys, Angular versions up to and including 1.3 **sort the keys alphabetically**.
38+
*
39+
* If this is not desired, the recommended workaround is to convert your object into an array
40+
* that is sorted into the order that you prefer before providing it to `ngRepeat`. You could
41+
* do this with a filter such as [toArrayFilter](http://ngmodules.org/modules/angular-toArrayFilter)
42+
* or implement a `$watch` on the object yourself.
43+
*
44+
* In version 1.4 we will remove the sorting, since it seems that browsers generally follow the
45+
* strategy of providing keys in the order in which they were defined, although there are exceptions
46+
* when keys are deleted and reinstated.
47+
*
48+
*
2649
* # Special repeat start and end points
2750
* To repeat a series of elements instead of just one parent element, ngRepeat (as well as other ng directives) supports extending
2851
* the range of the repeater by defining explicit start and end points by using **ng-repeat-start** and **ng-repeat-end** respectively.

0 commit comments

Comments
 (0)