Last active
October 27, 2017 03:41
-
-
Save cubicleWar/f6a444ea32b76e041f40 to your computer and use it in GitHub Desktop.
A function to apply a string of pipe separated filters to a given value using the angular $filter service.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // Applies a sequence of angular filters to a given variable | |
| // | |
| // @param $filter The angular filter service | |
| // @param value The variable to apply the filters on | |
| // @param filterSpec A pipe separated list of filters to apply to the value e.g "filter1|filter2|filerN" | |
| // | |
| function applyFilters($filter, value, filterSpec) | |
| { | |
| var filters = filterSpec.trim().split('|'), | |
| result = value; | |
| for (var i = 0, len = filters.length; i < len; i++) | |
| { | |
| var args = filters[i].trim().split(':'), | |
| filter = $filter(args.shift().trim()); | |
| args.unshift(result); | |
| result = filter.apply(null, args); | |
| } | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment