【发布时间】:2016-03-23 09:13:48
【问题描述】:
我正在使用 Angular 做一个 Web 应用程序,其中包含一个带有可折叠 tr 的表格。但是当我添加一些 ng-if 条件(如果数组中有/没有数据)时,ng-show 停止工作。
这是没有 ng-if 条件的工作代码:https://plnkr.co/edit/UPFF1RboN22RAVM8r18i?p=preview
<thead>
<tr role="row">
<th class="details-control sorting_disabled" rowspan="1" colspan="1" aria-label="" style="width: 26px;">
<th class="sorting_asc" tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-label="Projects: activate to sort column descending" aria-sort="ascending" style="width: 306px;">Foods</th>
<th class="sorting" tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-label=" EST: activate to sort column ascending" style="width: 84px;"><i class="fa fa-fw fa-user text-muted hidden-md hidden-sm hidden-xs"></i> Type</th>
<th class="sorting" tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-label="Contacts: activate to sort column ascending" style="width: 107px;">Count</th>
</tr>
</thead>
<tbody ng-repeat="data in allData" >
<tr>
<td>
<div class="cursor-pointer" ng-click="rows = !rows">
<!-- <span class="fa" ng-class="{'fa-caret-down': rows, 'fa-caret-right': !rows}"></span> -->
<p>open</p>
</div>
</td>
<td>{{data.foodName}}</td>
<td></td>
<td>{{data.totalCount}}</td>
</tr>
<tr ng-repeat="a in data.avaiable" ng-show="rows" ng-if="allData && allData.length > 0">
<td></td>
<td></td>
<td>{{a.foodType}}</td>
<td>{{a.foodCount}}</td>
</tr>
这是带有 ng-if 条件的无效代码。如果您在 plk https://plnkr.co/edit/IvlIXIfWpogNi5VXo2Eh?p=preview 看到,您会注意到行没有显示。为什么?
【问题讨论】:
-
在 2 例中显示 2 行有什么问题?
-
在第二个 plnkr 中,如果单击“打开”,它不会显示行
标签: javascript angularjs ng-show angular-ng-if