angular.js
angular.js copied to clipboard
limitTo filter should accept strings as well
Currently we support only arrays...
Do you mean something like this: 'abcde'.$limitTo(3) => 'abc' ? I can take care of that :)
Well, yes... but wait until Misko's injector is merged, as we changed this a bit... We don't augment the types anymore and limitTo is a filter instead...
sure
should be in master later today
wow, you are still working
To limit string size I use the following custom filter, you might be interested in:
/**
* Usage:
* {{some_text | cut:true:100:' ...'}}
* Options:
* - wordwise (boolean) - if true, cut only by words bounds,
* - max (integer) - max length of the text, cut to this number of chars,
* - tail (string, default: ' …') - add this string to the input
* string if the string was cut.
*/
angular.module('ng').filter('cut', function () {
return function (value, wordwise, max, tail) {
if (!value) return '';
max = parseInt(max, 10);
if (!max) return value;
if (value.length <= max) return value;
value = value.substr(0, max);
if (wordwise) {
var lastspace = value.lastIndexOf(' ');
if (lastspace != -1) {
value = value.substr(0, lastspace);
}
}
return value + (tail || ' …');
};
});