1

Hi I am trying to get a filter to return instances that have a certain quantity but can't seem to get it to work. What I have in my HTML:

I would like my filter to apply when I hit this checkbox:

<input type="checkbox" value="true" ng-model='filterSales' >

Heres what I have:

<div class='col-md-12' ng-repeat='sku in value | QuantityFilter'>

I was just able to learn how to create a custom filter but now I am having trouble figuring out how to toggle it.

1
  • If you want help, include what your QuantityFilter is, what filterSales is, and what value is. There isn't enough information to go on here to help you. Commented Jan 21, 2019 at 20:34

1 Answer 1

2

If you just want to know how you can see whether the checkbox is set or not, you can add a parameter to your filter function as shown in the example at the bottom of the documentation: https://docs.angularjs.org/api/ng/filter/filter

You would need to add :filterSales to your ng-repeat where you apply the filter.

<div class='col-md-12' ng-repeat='sku in value | quantityFilter:filterSales'>

In js you need to add another parameter, in this example "array" contains the array which is repeated (in your case "value") and toggleVar has the checkbox value.

"use strict";

app.filter("quantityFilter", function () {

    function quantityFilter(array, toggleVar) {
        if(!toggleVar){
            return array;
        }

        let result = [];

       // TODO: Build new array based on your criteria

        return result;
    }

    return quantityFilter;
});
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.