AngularJs:基于第一列中的下拉菜单显示/隐藏表列

时间:2019-05-02 18:02:53

标签: javascript angularjs

使用angularjs

我有一张表,其中第一列将其绑定到数组。

第二列是一个下拉列表。

我想根据第二列下拉菜单的值显示/隐藏其他5-6列(文本和下拉列表)。

我尝试了以下代码:

  <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"

但这仅在第一次有效。隐藏后不起作用。

任何人都可以指出我需要做些什么才能使它工作:

1 个答案:

答案 0 :(得分:2)

第一次设置utype!=undefined后,

ng-model="utype">始终为true。 取出utype!=undefined并尝试。

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

此外,imo,您应该使用===而不是'=='。有关详情,请参见此SO answer
例如ng-hide="utype ==='Type1'