korteee
korteee

Reputation: 2682

Apply filter based on select list - Angular JS

Array 1: Categories -> Category_Name, Category_Id

Array 2: Items -> Item_name ... etc , Category_Belonging_Id

I need to filter shown items based on selected category.

<div class="list>
    <select>
       <option ng-repeat="category in categories" ng-model="category_type">
          {{category.Category_Name}}
       </option>
    </select>

<a ng-repeat="item in items | filter: // What should I put here?" href="#">

...

</a>

</div>

Upvotes: 0

Views: 76

Answers (3)

Hassan Tariq
Hassan Tariq

Reputation: 740

Try this

<a ng-repeat="item in meatTypes | filter: {Category_Belonging_Id:category_type.Category_Id }"   href="#">

Upvotes: 0

Sanjay Nishad
Sanjay Nishad

Reputation: 1605

first of all you should use ng-option instead of ng-repeat like

<select ng-model="category_type" ng-options="category.Category_Name for category in categories"></select>

and use filter like

filter:{Category_Belonging_Id:category_type.Category_Id }

see demo here

Upvotes: 1

asdf_enel_hak
asdf_enel_hak

Reputation: 7640

Assuming you have:

Catergory = {
id 
name
}

and

MeatType{
    id
    catergoryId
    name
    }

You can do something like

<a ng-repeat="item in meatTypes | filter: {categoryId : catergory_type.id}" href="#">

Upvotes: 1

Related Questions