This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +14
-17
lines changed
docs/content/error/orderBy Expand file tree Collapse file tree 1 file changed +14
-17
lines changed Original file line number Diff line number Diff line change 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
1717To 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```
3832That 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```
You can’t perform that action at this time.
0 commit comments