From 37bc5ef4d87f19da47d3ab454c43d1e532c4f924 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Wed, 5 Feb 2014 23:50:58 -0500 Subject: fix(orderBy): support string predicates containing non-ident characters The orderBy filter now allows string predicates passed to the orderBy filter to make use property name predicates containing non-ident strings, such as spaces or percent signs, or non-latin characters. This behaviour requires the predicate string to be double-quoted. In markup, this might look like so: ```html
...
``` Or in JS: ```js var sorted = $filter('orderBy')(array, ['"Tip %"', '-"Subtotal $"'], false); ``` Closes #6143 Closes #6144 --- src/ng/filter/orderBy.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/ng/filter/orderBy.js b/src/ng/filter/orderBy.js index b6262698..faeb8ed1 100644 --- a/src/ng/filter/orderBy.js +++ b/src/ng/filter/orderBy.js @@ -74,6 +74,12 @@ function orderByFilter($parse){ predicate = predicate.substring(1); } get = $parse(predicate); + if (get.constant) { + var key = get(); + return reverseComparator(function(a,b) { + return compare(a[key], b[key]); + }, descending); + } } return reverseComparator(function(a,b){ return compare(get(a),get(b)); -- cgit v1.2.3