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 +53
-0
lines changed
docs/content/error/orderBy Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ @ngdoc error
2
+ @name orderBy:notarray
3
+ @fullName Not an array
4
+ @description
5
+
6
+ This error occurs when {@link ng.orderBy filter} is not used with an array:
7
+ ```html
8
+ <input ng-model="search">
9
+ <div ng-repeat="(key, value) in myObj | orderBy:search">
10
+ {{ key }} : {{ value }}
11
+ </div>
12
+ ```
13
+
14
+ orderBy must be used with an array so a subset of items can be returned.
15
+ The array can be initialized asynchronously and therefore null or undefined won't throw this error.
16
+
17
+ To orderBy an object by the value of its properties you can create your own array based on that object:
18
+ ```js
19
+ angular.module('aModule',[])
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
+ },
31
+ };
32
+
33
+ //if using underscore
34
+ $scope.objToArray = = _.values(obj);
35
+
36
+ });
37
+ ```
38
+ That can be used as:
39
+ ```html
40
+ <input ng-model="search">
41
+ <div ng-repeat="some in objToArray | orderBy:'name'">
42
+ {{ key }} : {{ value }}
43
+ </div>
44
+ ```
45
+
46
+ You could as well convert the object to an array using a filter such as
47
+ [toArrayFilter](https://github.com/petebacondarwin/angular-toArrayFilter):
48
+ ```html
49
+ <input ng-model="search">
50
+ <div ng-repeat="item in myObj | toArray:false | filter:search">
51
+ {{ item }}
52
+ </div>
53
+ ```
You can’t perform that action at this time.
0 commit comments