如何结合ng-if,ng-click和ng-show并一起使用它们

时间:2017-09-11 00:51:34

标签: javascript angularjs

预信息

我尝试在不同的阶段或视图中管理管理员和客户。

这样,管理员可以在将表发布给客户之前对其进行修改。

问题 在表格中 - > td 有按钮来控制升级,释放(显示)还是恢复(隐藏)?

基本上我想做的是每个检查的表都可以在admin和customer中显示。如果未选中,则仅向管理员显示数据。

目前,代码被禁用整个表体而不是1行。

有没有办法检查或取消选中只有一行?

感谢您的建议。

 $scope.showDiv = isAdmin();


        $scope.toggleShowDiv = function () {


            $scope.showDiv = !isAdmin()&isAdmin();
            console.log('fired');


        };
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<thead>
  <tr>
    <th style="width: 80px">foo1</th>
    <th style="width: 80px">foo2</th>
    <th style="width: 200px">foo3</th>
    <th>foo4</th>
    <th>foo5</th>
    <th>foo6</th>



  </tr>
</thead>
<tbody class="auction-group" ng-repeat="a in foos" ng-if="showDiv">
  <tr>
    <td>abcd1</td>
    <td>abcd1</td>
    <td>abcd1</td>
    <td>abcd3</td>

    <td>abcd4</td>
    <td>abcd5</td>

    //is admin - show only to admin
    <td ng-if="::isAdmin()">
      <input type="checkbox" ng-click="toggleShowDiv()" />

    </td>
  </tr>
</tbody>

1 个答案:

答案 0 :(得分:1)

取你的第一次ng-if外部ng-repeat

<div ng-if="showDiv">
   <tbody class="auction-group" ng-repeat="a in foos">
</div>

秒ng-if应该是这样的,

<td ng-if="isAdmin()">
      <input type="checkbox" ng-click="toggleShowDiv()" />
</td>
相关问题