Created
July 25, 2013 14:11
-
-
Save vitalyrotari/6080062 to your computer and use it in GitHub Desktop.
Angular Characters 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('app').filter('characters', function () { | |
return function(input, chars) { | |
if (isNaN(chars)) return input; | |
if (chars <= 0) return ''; | |
if(input && input.length >= chars) { | |
input = input.substring(0, chars); | |
var lastspace = input.lastIndexOf(' '); | |
//get last space | |
if (lastspace !== -1) { | |
input = input.substr(0, lastspace); | |
} | |
return input + '...'; | |
} | |
return input; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment