I have a list of items which I want to filter with radio buttons, here's an example of my array:
$scope.items = [
{
"name":"person 1",
"section":"one",
"job":false
},
{
"name":"person 2",
"section":"two",
"job":true
},
{
"name":"person 3",
"section":"one",
"job":false
},
{
"name":"person 4",
"section":"one",
"job":true
}
];
In my HTML, I have an ng-repeat list which I want to filter with radio buttons:
<div class="menu">
<label>
<input type="radio" ng-model="filteradio.section" value="">
<p>All</p>
</label>
<label>
<input type="radio" ng-model="filteradio.section" value="one">
<p>Section 1</p>
</label>
<label>
<input type="radio" ng-model="filteradio.section" value="two">
<p>Section 2</p>
</label>
<label>
<input type="radio" ng-model="filteradio.job" value="true">
<p>People with job</p>
</label>
</div>
<table>
<tr>
<td>Name</td>
<td>Section</td>
<td>Job</td>
</tr>
<tr ng-repeat="item in items | filter:filteradio:strict">
<td>{{item.name}}</td>
<td>{{item.section}}</td>
<td ng-if="item.job">yes</td>
</tr>
</table>
The problem is that the last radio button won't work, because when I select the buttons with "filteradio.section" they work fine, but once I click in the "filteradio.job" the other radio buttons stay checked!
I tried adding the same "name atribute" to all radio buttons but this way once I click "filteradio.job" all items dissapear.
How can I filter them all by "section" and also by "if they have a job or not"? Is there an easier way to approach this?