diff --git a/src/ng/filter/orderBy.js b/src/ng/filter/orderBy.js index 32b438517f97..fa86b971afd8 100644 --- a/src/ng/filter/orderBy.js +++ b/src/ng/filter/orderBy.js @@ -175,9 +175,9 @@ function orderByFilter($parse){ v2 = v2.toLowerCase(); } if (v1 === v2) return 0; - return v1 < v2 ? -1 : 1; + return v1 > v2 ? 1 : -1; } else { - return t1 < t2 ? -1 : 1; + return t1 > t2 ? 1 : -1; } } }; diff --git a/test/ng/filter/orderBySpec.js b/test/ng/filter/orderBySpec.js index 76159efe61e2..03a3c3519d78 100644 --- a/test/ng/filter/orderBySpec.js +++ b/test/ng/filter/orderBySpec.js @@ -20,6 +20,13 @@ describe('Filter: orderBy', function() { expect(orderBy([2, 1, 3], ['-'])).toEqual([3, 2, 1]); }); + it('should maintain order in an array of objects if no predicate is provided', function() { + expect(orderBy([{a: 1}, {b: 2}, {c: 3}])).toEqualData([{a: 1}, {b: 2}, {c: 3}]); + expect(orderBy([{a: 1}, {b: 2}, {c: 3}], '')).toEqualData([{a: 1}, {b: 2}, {c: 3}]); + expect(orderBy([{a: 1}, {b: 2}, {c: 3}], [])).toEqualData([{a: 1}, {b: 2}, {c: 3}]); + expect(orderBy([{a: 1}, {b: 2}, {c: 3}], [''])).toEqualData([{a: 1}, {b: 2}, {c: 3}]); + }); + it('shouldSortArrayInReverse', function() { expect(orderBy([{a:15}, {a:2}], 'a', true)).toEqualData([{a:15}, {a:2}]); expect(orderBy([{a:15}, {a:2}], 'a', "T")).toEqualData([{a:15}, {a:2}]);