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

Commit ebb719b

Browse files
committed
chore(orderBy): Update documentation based on code review.
1 parent 25e492b commit ebb719b

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

Diff for: docs/content/error/orderBy/notarray.ngdoc

+14-17
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@fullName Not an array
44
@description
55

6-
This error occurs when {@link ng.orderBy filter} is not used with an array:
6+
This error occurs when {@link ng.orderBy orderBy} is not used with an array:
77
```html
88
<input ng-model="search">
99
<div ng-repeat="(key, value) in myObj | orderBy:search">
@@ -16,29 +16,26 @@ The array can be initialized asynchronously and therefore null or undefined won'
1616

1717
To orderBy an object by the value of its properties you can create your own array based on that object:
1818
```js
19-
angular.module('aModule',[])
19+
angular.module('aModule', [])
2020
.controller('aController', function($scope) {
21-
var obj = {
22-
one: {
23-
name: 'something 1'
24-
},
25-
two: {
26-
name: 'something 2'
27-
},
28-
three: {
29-
name: 'something 3'
30-
},
21+
var myObj = {
22+
one: {id: 1, name: 'Some thing'},
23+
two: {id: 2, name: 'Another thing'},
24+
three: {id: 3, name: 'A third thing'}
3125
};
3226

33-
//if using underscore
34-
$scope.objToArray = = _.values(obj);
35-
27+
$scope.arrFromMyObj = Object.keys(myObj).map(function(key) {
28+
return myObj[key];
29+
});
3630
});
3731
```
3832
That can be used as:
3933
```html
40-
<input ng-model="search">
41-
<div ng-repeat="some in objToArray | orderBy:'name'">
34+
<label>
35+
Order by:
36+
<select ng-model="orderProp" ng-options="prop for prop in ['id', 'name']"></select>
37+
</label>
38+
<div ng-repeat="(key, value) in myObj | orderBy:orderProp">
4239
{{ key }} : {{ value }}
4340
</div>
4441
```

0 commit comments

Comments
 (0)