Boris B. Manzhela Boris B. Manzhela - 1 year ago 66
AngularJS Question

How to filter data by only one value in Angular?

I have a working example of multiple filter (view at CodePen) to sort amont of data by Material and Construction parameters.

<select multiple="multiple" ng-model="selectedMaterial" ng-options="emp.material as emp.material for emp in empList | unique:'material'">

<table class="table table-bordered">
<tr ng-repeat="emp in empList | filterMultiple:{material:selectedMaterial,construction:selectedConstruction}">

But this is a question: what i need to do to filter that data by pushing on buttons? Coz my solution not working...

<button ng-click="filterMultiple= {material: 'Steel'}">Steel</button>

Thank you!

Answer Source

Try something like this:

<tr ng-repeat="emp in empList | filter:{material:selectedMaterial,construction:selectedConstruction}">

<button ng-click="selectedMaterial = 'Steel'">Steel</button>

Hope it helps :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download