0

So I have a dropdown..

<select ng-model="dropdown">
    <option ng-value="1">1</option>
    <option ng-value="2">2</option>
    <option ng-value="all">All</option>
</select>

and a table..

<table>
    <tr ng-repeat="d in data">
        <td ng-bind="d.number"></td> // 0 or 1
        <td>Other TD's</td>
        <td>Other TD's</td>
    </tr>
</table>

What I wanted to do is to when I select for example number 2 in the dropdown, all other rows in the table will be hidden except the row with ng-bind="d.number" that is equal to 2.

So what I tried so far is this

<table>
    <tr ng-repeat="d in data" ng-if="d.number == dropdown">
        <td ng-bind="d.number"></td> // 0 or 1
        <td>Other TD's</td>
        <td>Other TD's</td>
    </tr>
</table>

But when I select all in the dropdown, the table is empty already.

Is there a cleaner way to do this? Thanks in advance.

2
  • maybe have you tried something like: <tr ng-repeat="d in data" ng-if="d.number == dropdown || d.number == 'all'"> Commented Jan 7, 2017 at 15:11
  • 1
    maybe use filter? something like that <tr ng-repeat="d in data | filter:{number:dropdown}" Commented Jan 7, 2017 at 15:12

1 Answer 1

1

You can use the angular filter to do that like below : Plunkr

<table>
<tr ng-repeat="d in data | filter: {number: dropdown||undefined}">
 <td ng-bind="d.number"></td> // 0 or 1
 <td>Other TD's</td>
 <td>Other TD's</td>
</tr>
</table>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.