Created
March 11, 2015 11:16
-
-
Save Kichrum/42f10f5d858e73b2a5e5 to your computer and use it in GitHub Desktop.
Angular.js filter for adding custom values in brackets
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
(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