From 2d9e96772fd03cdd756e8f0d1f00ba4d205c3ba6 Mon Sep 17 00:00:00 2001 From: zainengineer Date: Wed, 28 May 2014 04:33:43 +0930 Subject: [PATCH] docs(orderBy): add example of directly calling $filter('orderBy') It's not a bad example of sorting fields in a table, which is something people are frequently wanting to do. So I say, LGTM! ~caitp, 1988-2014 --- src/ng/filter/orderBy.js | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/ng/filter/orderBy.js b/src/ng/filter/orderBy.js index 319950a1a..9a48ebae7 100644 --- a/src/ng/filter/orderBy.js +++ b/src/ng/filter/orderBy.js @@ -61,6 +61,51 @@ + * + * It's also possible to call the orderBy filter manually, by injecting `$filter`, retrieving the + * filter routine with `$filter('orderBy')`, and calling the returned filter routine with the + * desired parameters. + * + * Example: + * + * @example + + +
+ + + + + + + + + + + +
Name + (^)Phone NumberAge
{{friend.name}}{{friend.phone}}{{friend.age}}
+
+
+ + + function Ctrl($scope, $filter) { + var orderBy = $filter('orderBy'); + $scope.friends = [ + { name: 'John', phone: '555-1212', age: 10 }, + { name: 'Mary', phone: '555-9876', age: 19 }, + { name: 'Mike', phone: '555-4321', age: 21 }, + { name: 'Adam', phone: '555-5678', age: 35 }, + { name: 'Julie', phone: '555-8765', age: 29 } + ]; + + $scope.order = function(predicate, reverse) { + $scope.friends = orderBy($scope.friends, predicate, reverse); + }; + $scope.order('-age',false); + } + +
*/ orderByFilter.$inject = ['$parse']; function orderByFilter($parse){