|
34 | 34 | * @param {boolean=} reverse Reverse the order of the array.
|
35 | 35 | * @returns {Array} Sorted copy of the source array.
|
36 | 36 | *
|
| 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. |
37 | 74 | * @example
|
38 | 75 | <example module="orderByExample">
|
39 | 76 | <file name="index.html">
|
|
0 commit comments