Creating a custom AngularJS filter to display items between values

Sometimes you need to filter out certain items in a list based on a numeric value. The following code accomplish that.

Put this into your controller:

    // Comparison filter
    $scope.inBetween = function (property, lowbound, highbound) {
        return function (item) {
            if (item[property] >= lowbound && item[property] <= highbound) return true;
            return false;

And then you just use the filter in the following way in your ng-repeat:

<tr ng-repeat="a in Result | filter: inBetween('accountnumber', 10100000, 15000000)">

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s