0

I am trying to create a filter for AngularJS data. I have 2 inputs, minAgeInput and maxAgeInput.

I would like to return all products/objects (with ng-repeat), where the product's minAge and maxAge are within the boundaries set by the input values.

My filter function looks like this:
or link to Plunker

$scope.ageRange = function (plane) {
var minAgeProduct = parseFloat(product.minAge);
var maxAgeProduct = parseFloat(product.maxAge);
var minAgeInput = parseFloat($scope.minAge);
var maxAgeInput = parseFloat($scope.maxAge);

if(minAgeInput >= minAgeProduct) {
    if(maxAgeInput <= maxAgeProduct) {
        return true;
    } else {
        return false;
    }
    return true;
} else {
    return false;
}
};
4
  • Seems like someone asked about the same question : stackoverflow.com/questions/30858071/… :) Commented Jun 16, 2015 at 3:34
  • @sirrocco, seems like I answered to the same question twice. Commented Jun 16, 2015 at 3:36
  • Yeap ... maybe it was a contest in the office - who can ask the question fastest :)) Commented Jun 16, 2015 at 3:37
  • @sirrocco, Hahaha that was actually really funny :) But unfortunately not the case (I'm working on a solo project) Commented Jun 16, 2015 at 6:37

1 Answer 1

0

Here is the functional solution to the question:

$scope.ageRange = function (plane) {
    var minAgeProduct = parseFloat(plane.minAge);
    var maxAgeProduct = parseFloat(plane.maxAge);
    var minAgeInput = parseFloat($scope.minAge);
    var maxAgeInput = parseFloat($scope.maxAge);

    if (!isNaN(minAgeInput) && maxAgeProduct < minAgeInput)
        return false;

    if (!isNaN(maxAgeInput) && minAgeProduct > maxAgeInput)
        return false;

    return true;
};

A working solution can be found here Plunker

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.