1

Using angularjs

I have a table which column one I am binding it to a an array.

Second column is a dropdown.

I want to have other 5-6 columns (text and dropdown) which I want to show/hide based on the value of second column dropdown.

I tried the below code:

  <table class="table table-bordered">
    <thead>
    <tr>
        <th>Name</th>
        <th>Value</th>
        <th></th>
    </tr>
    </thead>
    <tbody>
    <tr ng-repeat="item in items">
       <td >{{item.name}}</td>
       <td >  
          <select name="utype" class="form-control input-medium"  ng-model="utype">
                  <option value="">---Please select---</option>
                  <option ng-repeat="type in types" >{{type.text}}</option>
          </select></td>
      <td><span ng-hide="utype =='Type1' || utype!=undefined" >{{item.value}}</span></td>
      <td><button class="btn btn-small" ng-click="edit(item)">Edit</button></td>
    </tr>
    </tbody>
  </table>

ng-hide="utype =='Type1' || utype!=undefined"

But this only works the first time. After hiding it does not work.

Could anyone point what I need to do to make it work:

1 Answer 1

1

utype!=undefined is always true after you set ng-model="utype"> the first time. Take out utype!=undefined and try it.

<td><span ng-hide="utype =='Type1' >{{item.value}}</span></td>

Also, imo, you should use === rather than '=='. see this SO answer for details.
e.g.. ng-hide="utype ==='Type1'

Sign up to request clarification or add additional context in comments.

3 Comments

This does not work. That column is now hidden and doesnt show even after changing ddl value
post your new code. And what are the values in your array?
If the expression in ng-hide is evaluating to true then the <td> will be hidden. Check that your expression ng-hide="utype ==='Type1' is evaluating to true/false correctly. To check this, put this line somewhere in your hmtl ng-hide value is {{utype ==='Type1'}} `

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.