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

Commit 770a4dd

Browse files
edthedevNarretz
authored andcommitted
docs(orderBy): Start with a simpler example.
Per the question raised at this Stack Overflow question: http://stackoverflow.com/questions/24048590/angularjs-ng-repeat-orderby-date-not-working The first example on this page is too complex to convey the simplest possible case for using this function. Closes #11144
1 parent f6b51fc commit 770a4dd

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/ng/filter/orderBy.js

+37
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,43 @@
3434
* @param {boolean=} reverse Reverse the order of the array.
3535
* @returns {Array} Sorted copy of the source array.
3636
*
37+
*
38+
* @example
39+
* The example below demonstrates a simple ngRepeat, where the data is sorted
40+
* by age in descending order (predicate is set to `'-age'`).
41+
* `reverse` is not set, which means it defaults to `false`.
42+
<example module="orderByExample">
43+
<file name="index.html">
44+
<script>
45+
angular.module('orderByExample', [])
46+
.controller('ExampleController', ['$scope', function($scope) {
47+
$scope.friends =
48+
[{name:'John', phone:'555-1212', age:10},
49+
{name:'Mary', phone:'555-9876', age:19},
50+
{name:'Mike', phone:'555-4321', age:21},
51+
{name:'Adam', phone:'555-5678', age:35},
52+
{name:'Julie', phone:'555-8765', age:29}];
53+
}]);
54+
</script>
55+
<div ng-controller="ExampleController">
56+
<table class="friend">
57+
<tr>
58+
<th>Name</th>
59+
<th>Phone Number</th>
60+
<th>Age</th>
61+
</tr>
62+
<tr ng-repeat="friend in friends | orderBy:'-age'">
63+
<td>{{friend.name}}</td>
64+
<td>{{friend.phone}}</td>
65+
<td>{{friend.age}}</td>
66+
</tr>
67+
</table>
68+
</div>
69+
</file>
70+
</example>
71+
*
72+
* The predicate and reverse parameters can be controlled dynamically through scope properties,
73+
* as shown in the next example.
3774
* @example
3875
<example module="orderByExample">
3976
<file name="index.html">

0 commit comments

Comments
 (0)