2

I'm trying to perform an advanced search with an angular filter. The idea of the filter is to receive two values (maximum and minimum) in an array and copy all intervals that are within the maximum and minimum of another array.

example: array = {20,32,10, 60, 75, 43, 95}

minimum: 50 maximum: 100

resultant vector = {60, 95} 75.

code:

 for (var i = 0; i < products.length; i++) {
        if (product[i].precio >= $scope.minimo && product[i].precio <= $scope.maximo)
            return this.products[i];
    }
    return null;
};
1
  • you mean to create a custom filter right Commented Jun 16, 2015 at 3:03

1 Answer 1

1

Something like:

angular.filter('someFilter', function() {
    var newArray = [];
    return function(products, min, max) {
        for(var i = 0; i < products.length, i++) {
            if (products[i].precio >= min && products[i].precio <= max) {
                newArray.push(products[i]);
            }
        }
        return newArray;
    };
});

And use it like: <... ng-repeat="products | someFilter:min:max" ...>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.