This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 1 file changed +14
-17
lines changed
docs/content/error/orderBy
1 file changed +14
-17
lines changed Original file line number Diff line number Diff line change 3
3
@fullName Not an array
4
4
@description
5
5
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:
7
7
```html
8
8
<input ng-model="search">
9
9
<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'
16
16
17
17
To orderBy an object by the value of its properties you can create your own array based on that object:
18
18
```js
19
- angular.module('aModule',[])
19
+ angular.module('aModule', [])
20
20
.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'}
31
25
};
32
26
33
- //if using underscore
34
- $scope.objToArray = = _.values(obj) ;
35
-
27
+ $scope.arrFromMyObj = Object.keys(myObj).map(function(key) {
28
+ return myObj[key] ;
29
+ });
36
30
});
37
31
```
38
32
That can be used as:
39
33
```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">
42
39
{{ key }} : {{ value }}
43
40
</div>
44
41
```
You can’t perform that action at this time.
0 commit comments