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

Commit a65d3a4

Browse files
committed
fix(orderBy): Modify docs and add test for array-like object.
BREAKING CHANGES: These changes alter the behavior of AngularJS such that it will no longer throw an error for non array values, as it will accept array-like values as well. It will throw an error if no array-like value is passed.
1 parent ebb719b commit a65d3a4

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

docs/content/error/orderBy/notarray.ngdoc

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
@ngdoc error
22
@name orderBy:notarray
3-
@fullName Not an array
3+
@fullName Value is not array-like
44
@description
55

6-
This error occurs when {@link ng.orderBy orderBy} is not used with an array:
6+
This error occurs when {@link ng.orderBy orderBy} is not passed an array-like value:
77
```html
88
<input ng-model="search">
99
<div ng-repeat="(key, value) in myObj | orderBy:search">
1010
{{ key }} : {{ value }}
1111
</div>
1212
```
1313

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.
14+
orderBy must be used with an array-like value 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.
1616

17-
To orderBy an object by the value of its properties you can create your own array based on that object:
17+
To use orderBy to order the properties of an object, you can create your own array based on that object:
1818
```js
1919
angular.module('aModule', [])
2020
.controller('aController', function($scope) {

test/ng/filter/orderBySpec.js

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ describe('Filter: orderBy', function() {
1313
toThrowMinErr('orderBy', 'notarray', 'Expected array but received: {}');
1414
});
1515

16+
it('should not throw an exception if an array-like object is provided', function() {
17+
expect(orderBy('cba')).toEqual(['a', 'b', 'c']);
18+
});
19+
1620
it('should return sorted array if predicate is not provided', function() {
1721
expect(orderBy([2, 1, 3])).toEqual([1, 2, 3]);
1822

0 commit comments

Comments
 (0)