Boris B. Manzhela Boris B. Manzhela - 2 months ago 6
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'">
</select>

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


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

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 :)

Comments