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

Object limitTo filter not native ot AngularJS? #6300

@RavenHursT

Description

@RavenHursT

Why isn't something like this native to AngularJS? Seems rather simple to implement...

Filter:

.filter('objLimitTo', [function(){
        return function(obj, limit){
            var keys = Object.keys(obj);
            if(keys.length < 1){
                return [];
            }

            var ret = new Object,
                count = 0;

            angular.forEach(keys, function(key, arrayIndex){
                console.log(key);
                if(count >= limit){
                    return false;
                }
                ret[key] = obj[key];
                count++;
            });

            return ret;
        };
    }])

Markup:

<ul>
<li ng-repeat="(k, v) in items | objLimitTo:4">{{ v}} </l>
</li>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions