Created
August 13, 2016 08:39
-
-
Save shershen08/46d2f4a2ab17c94d6ed565c2e7079b53 to your computer and use it in GitHub Desktop.
Angular1 custom filters
This file contains 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
angular.module('myApp', []) | |
/** | |
* concat | |
* transforms array [a,b,c] to a template string list 'a,b,c' | |
* */ | |
.filter('concat', function() { | |
return function(input, property) { | |
var out = ''; | |
for (var i = 0; i < input.length; i++) { | |
out += input[i][property] ? input[i][property] : input[i]; | |
if (i < (input.length - 1)) out += ', '; | |
} | |
return out; | |
}; | |
}) | |
/** | |
* placeholder | |
* shows a placeholder in the template if the main value is undefined | |
* */ | |
.filter('placeholder', function() { | |
return function(input, property) { | |
return (input == undefined || input == '') ? property : input; | |
}; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment