This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
limitTo filter should accept strings as well #653
Labels
Comments
Do you mean something like this: 'abcde'.$limitTo(3) => 'abc' ? |
Well, yes... but wait until Misko's injector is merged, as we changed this a bit... |
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 || ' …');
};
}); |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Currently we support only arrays...
The text was updated successfully, but these errors were encountered: