diff --git a/src/ng/filter/orderBy.js b/src/ng/filter/orderBy.js index cd66d5ca838d..e396c8fa1d8c 100644 --- a/src/ng/filter/orderBy.js +++ b/src/ng/filter/orderBy.js @@ -115,7 +115,7 @@ orderByFilter.$inject = ['$parse']; function orderByFilter($parse){ return function(array, sortPredicate, reverseOrder) { - if (!isArray(array)) return array; + if (!isArrayLike(array)) return array; if (!sortPredicate) return array; sortPredicate = isArray(sortPredicate) ? sortPredicate: [sortPredicate]; sortPredicate = map(sortPredicate, function(predicate){ diff --git a/test/ng/filter/orderBySpec.js b/test/ng/filter/orderBySpec.js index c97ea43700b1..0ca459cfa5f8 100644 --- a/test/ng/filter/orderBySpec.js +++ b/test/ng/filter/orderBySpec.js @@ -17,6 +17,19 @@ describe('Filter: orderBy', function() { expect(orderBy([{a:15}, {a:2}], 'a', "reverse")).toEqualData([{a:15}, {a:2}]); }); + it('should sort inherited from array', function(){ + function BaseCollection(){} + BaseCollection.prototype = Array.prototype; + var child = new BaseCollection(); + child.push({a:2}); + child.push({a:15}); + + expect(Array.isArray(child)).toBe(false); + expect(child instanceof Array).toBe(true); + + expect(orderBy(child, 'a', true)).toEqualData([{a:15}, {a:2}]); + }); + it('should sort array by predicate', function() { expect(orderBy([{a:15, b:1}, {a:2, b:1}], ['a', 'b'])).toEqualData([{a:2, b:1}, {a:15, b:1}]); expect(orderBy([{a:15, b:1}, {a:2, b:1}], ['b', 'a'])).toEqualData([{a:2, b:1}, {a:15, b:1}]);