Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

limitTo filter should accept strings as well #653

Closed
vojtajina opened this issue Nov 14, 2011 · 6 comments
Closed

limitTo filter should accept strings as well #653

vojtajina opened this issue Nov 14, 2011 · 6 comments

Comments

@vojtajina
Copy link
Contributor

Currently we support only arrays...

@Codier
Copy link
Contributor

Codier commented Nov 14, 2011

Do you mean something like this: 'abcde'.$limitTo(3) => 'abc' ?
I can take care of that :)

@vojtajina
Copy link
Contributor Author

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...

@Codier
Copy link
Contributor

Codier commented Nov 15, 2011

sure

@mhevery
Copy link
Contributor

mhevery commented Nov 15, 2011

should be in master later today

@Codier
Copy link
Contributor

Codier commented Nov 15, 2011

wow, you are still working

@kstep
Copy link
Contributor

kstep commented Jan 20, 2012

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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants