有没有什么方法可以启用/禁用Angular中表格中列的显示?

时间:2013-08-04 17:30:52

标签: angularjs

我有以下内容:

<select
    data-ng-model="option.selectedValue"
    data-ng-options="item.id as item.name for item in option.selects">
</select>

<table>
    <thead>
        <tr>
            <th>Id</th>
            <th>City</th>
            <th>Street</th>
        </tr>
    </thead>
    <tbody class="grid">
        <tr data-ng-repeat="row in grid.data">
            <td>{{ row.iD }}</td>
            <td>{{ row.city }}</td>
            <td>{{ row.street }}</td>
        </tr>
    </tbody>
</table>

我有办法更改它,这样只有当option.selectedValue等于0

时才能看到街道列

2 个答案:

答案 0 :(得分:3)

{{row.street}}street

上试试这个
<th ng-show='option.selectedValue == 0'>Street</th>
...
<td ng-show='option.selectedValue == 0'>{{row.street}}</td>

<th ng-hide="option.selectedValue != 0">Street</th>
...
<td ng-hide='option.selectedValue != 0'>{{row.street}}</td>

它是一样的;)

答案 1 :(得分:1)

使用ng-show。您需要隐藏header columncontent column

<th ng-show="option.selectedValue == 0">Street</th>
<td ng-show="option.selectedValue == 0">{{ row.street }}</td>

Demo