Skip to content

Instantly share code, notes, and snippets.

@Kichrum
Created March 11, 2015 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kichrum/42f10f5d858e73b2a5e5 to your computer and use it in GitHub Desktop.
Save Kichrum/42f10f5d858e73b2a5e5 to your computer and use it in GitHub Desktop.
Angular.js filter for adding custom values in brackets
(function(angular) {
var addCustomValuesFilter = function () {
// string | addCustomValues : true : 1 : 2
return function () {
var input = arguments[0],
shouldApplyFilter = arguments[1] !== false,
i, len,
values = [],
result = input;
if (shouldApplyFilter) {
for (i = 2, len = arguments.length; i < len; i++) {
if (arguments[i] !== null) {
values.push(arguments[i]);
}
}
if (values.length) {
result = input + ' (' + values.join(', ') + ')';
}
}
return result;
};
};
angular.module('addCustomValuesFilter', [])
.filter('addCustomValues', addCustomValuesFilter);
})(angular);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment