0

How to pass array of values as filter in angularjs

My scenario

cuisines json: ["food", "Alcohol","Thai"]

catorigeres json :["home", "office","school"]

values with cuisines and categories :

[{
    "_id": "1",
    "businessTypeName": "Pizza Hut",
    "cus_name": ["food","Thai"],
    "cat_name": ["home", "school"],

}, {
    "_id": "2",
    "businessTypeName": "Chicken Hut",
    "cus_name":["Alcohol","Thai"],
    "cat_name": ["office", "home"],
}, {
    "_id": "3",
    "businessTypeName": "Fish Hut",
    "bussiness_url": "/dist/images/loop_image_sample_3.png",
    "cus_name": ["Thai"],
    "cat_name": ["office", "school"],

}]

cuisines and categories are of in checkbox if i click anyone it will append the array of values to {{selected}}

my question is how to filter values in {{selected}} to listing_loop div

my plunker demo

3
  • stackoverflow.com/questions/37188106/… Commented Nov 9, 2016 at 14:31
  • yes see that can you explain how can we do it in my scenario ? Commented Nov 9, 2016 at 14:36
  • @RamanaaGj, have you checked the plunker? Commented Nov 9, 2016 at 18:26

1 Answer 1

0

I don't think you can do that in html alone.

You can add a filtering function to the scope:

$scope.customFilter = function(value, index, array) {
      // make sure `value.id` is a string
      return ["food","Thai","Alcohol"].indexOf(value.id);
}

and using like this in HTML

<div ng-repeat="set in get | filter:customFilter"></div>
Sign up to request clarification or add additional context in comments.

4 Comments

your plunker doesn't have <div ng-repeat="set in get..."></div> in it. add the full example, and I'll update with the filter, or do it yourself, it's just a few lines. If helped, you can upvote or accept my answer
i have three api values one for categories ["home","office","school"] and cuisines["food","Alcohol","Thai","Asian"] and all values as in this api https://api.myjson.com/bins/4m12o cuisines and categories are of in checkbox if i selected those values means it will come to {{selected}} array in that {{selected}} array i want to filter out from all values .. i think you may understood what i except
do you want to filter by cat_name or cus_name?
want filter by cat_name

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.